2010-10-01 65 views
7

谷歌是在暗示,开发商可能想混淆字节码:如何关闭除混淆之外的所有Android ProGuard功能?

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

我跟谷歌的指示得到一个模糊的Android应用程序,乍一看,似乎工作。但是有一些奇怪的错误引入了未被模糊处理的应用程序。我一直关闭ProGuard的选择,让这个配置:

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

仍然是错误的存在。还有什么我可以关闭只获得纯粹的混淆?混淆会很好,但我愿意关闭ProGuard的其他功能。

+0

嗨!你有没有找到解决你的问题?我也面临同样的问题。 https://stackoverflow.com/questions/47716524/proguard-android-execution-failed-for-task-presentationtransformclasseswith – yozhik 2017-12-08 14:51:26

回答

7

这是我用:

-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 

它混淆,但保持公众对Android的需要的类的公共方法和类的名称。按照您的要求,它不会进行优化 - 由于删除方法和构造函数,优化更可能会破坏您的程序。

如果您想尝试,包括优化这里就是我(记得去掉上面的-dontoptimize选项)

#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,但其他版本可能工作得很好。