You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何保留AAR库中静态方法名并混淆方法内部代码?

Hey there! Let's tackle your ProGuard confusion (pun intended) step by step.

First, to answer your core question: Yes, -keepclassmembernames absolutely lets ProGuard obfuscate all code inside your MyFunc method. This rule only protects the method's name from being renamed—it doesn't touch anything inside the method body. Variables, logic flow, even unused code will still get obfuscated and optimized just like normal. Perfect for your use case.

Now, why didn't your original rules work? Let's break that down:
Your rule -keep,allowobfuscation class * is actually redundant here. -keepclassmembernames already ensures your target method names stay intact, and class names are obfuscated by default unless you explicitly preserve them. The bigger issue might be that your -keepclassmembers rule was too narrow (public static void * (...))—it only targets public static methods with a void return type. If you had methods with other return types, their names would still get obfuscated. Even for void methods, if you weren't seeing internal obfuscation, double-check you haven't accidentally added -dontobfuscate or -dontoptimize (these disable the core obfuscation/optimization steps entirely).

Correct ProGuard Configuration

Here's the clean, targeted setup to meet your needs:

# Adjust optimization passes based on your needs (5 is a reasonable default)
-optimizationpasses 5

# Keep names of ALL public static methods across all classes
# Method bodies will still be fully obfuscated and optimized
-keepclassmembernames class * {
    public static <methods>;
}

# If you only need to target public static void methods (like your MyFunc example), use this instead:
# -keepclassmembernames class * {
#     public static void *(...);
# }

How to Verify

Use a decompiler like JD-GUI on your obfuscated AAR/APK to confirm:

  • The MyFunc method name remains unchanged
  • Inside the method, local variables will be renamed to single letters (e.g., a, b)
  • Unnecessary code will be stripped and logic will be simplified

内容的提问来源于stack exchange,提问作者Fresco

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:42:47