gpt4 book ai didi

android - 如何关闭除混淆之外的所有 Android ProGuard 功能?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:53:05 26 4
gpt4 key购买 nike

Google 建议开发人员可能希望混淆字节码:

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

我按照 Google 的说明获得了一个经过混淆的 Android 应用程序,乍一看,它似乎可以正常工作。但是引入了一些奇怪的错误,这些错误不在未混淆的应用程序中。我一直关闭 ProGuard 选项以获取此配置:

-dontoptimize-不要缩水-dontusemixedcaseclassnames-不要跳过非公共(public)图书馆类(class)-不要预先验证-冗长

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

最佳答案

这是我用的:

-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 所需类的公共(public)方法和类名。正如您所要求的那样,它不会优化 - 由于删除了方法和构造函数,优化更有可能破坏您的程序。

如果你想尝试包括优化这就是我所做的(记得删除上面的 -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,但其他版本可能也能正常工作。

关于android - 如何关闭除混淆之外的所有 Android ProGuard 功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3843093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com