如何关闭所有的Andr​​oid ProGuard的功能,除了混淆?有的、功能、oid、Andr

2023-09-05 00:49:42 作者:断片

谷歌是在暗示,开发商可能想混淆字节code:

Google is suggesting that developers might want to obfuscate byte code:

http://android-developers.blogspot.com/2010/09/proguard-android-and-licensing-server.html

我跟谷歌的指令来获取模糊化的Andr​​oid应用程序的,乍看之下,似乎工作。但也有一些奇怪的错误介绍,不在非混淆的应用程序。我一直关闭ProGuard的选项来获得这种配置:

I followed Google's instructions to get an obfuscated Android app that, at first glance, seemed to work. But there were some strange bugs introduced that are not in the un-obfuscated app. I kept turning off ProGuard options to get to this configuration:

-dontoptimize -dontshrink -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dont preverify -verbose

-dontoptimize -dontshrink -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose

不过的错误在那里。还有什么我可以关闭以获得唯一的纯混淆?模糊处理将是不错,但我愿意关闭的ProGuard的其他功能。

Still the bugs are there. Is there anything else I can turn off to get only pure obfuscation? Obfuscation would be nice, but I am willing to turn off ProGuard's other features.

推荐答案

这是我使用的:

-libraryjars ${android.jar}
-injars      temp.jar
-outjars    proguard.jar

#-printseeds: Prints the un-obfuscated filenames
-printseeds
-printmapping mapping-used-to-retrace-exceptions.txt
-verbose

#-dontusemixedcaseclassnames: Necessary when building on windows where x.class and X.class is the same file
-dontusemixedcaseclassnames

#-repackageclasses: Adds further obfuscation, Counter-indication: classes that look for resource files in their package directories will no longer work properly if they are moved elsewhere. When in doubt, just leave the packaging untouched by not using this option.
-repackageclasses ''

#-dontskipnonpubliclibraryclasses: Counter-indication: you probably shouldn't use this option when processing code that is to be used as a library, since classes and class members that weren't designed to be public in the API may become public.
-dontskipnonpubliclibraryclasses

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep class * extends android.view.View { 
  public <init>(android.content.Context); 
  public <init>(android.content.Context, android.util.AttributeSet); 
  public <init>(android.content.Context, android.util.AttributeSet, int); 
  public void set*(...); 
}
-keep class * extends android.preference.Preference { 
  public <init>(android.content.Context); 
  public <init>(android.content.Context, android.util.AttributeSet); 
  public <init>(android.content.Context, android.util.AttributeSet, int); 
  public void set*(...); 
}    
# LVL License binder class
-keep class com.android.vending.licensing.ILicensingService    
# This is necessary for LVL among others. According to proguard doc java accesses enum fields by introspection.
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
#Optimization settings
-dontoptimize

据混淆,但保持公众需要的安卓类的公共方法和类的名称。当你要求它不优化 - 优化更有可能你的程序打破由于去除方法和构造函数。

It obfuscates but keeps public the public methods and class name of classes needed by Android. As you requested it does not optimize - optimizations are more likely to break your program due to removed methods and constructors.

如果您想尝试,包括优化这里的我(记得删除-dontoptimize选项上)什么

If you want to try out including optimizations here's what I do (remember to remove the -dontoptimize option above)

#Optimization settings    
# Keep (ie. don't remove) all public constructors of all public classes, but still obfuscate+optimize their content. This is necessary because optimization removes constructors which I use through reflection.
-keepclassmembers class * {
    <init>(...);
}

-optimizationpasses 7
-allowaccessmodification
# The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. 
-optimizations !code/simplification/arithmetic 

我使用ProGuard的4.5,但是其他版本可能工作也很好。

I use proguard 4.5, but other versions probably work just as well.