0

如何使用 proguard 混淆 android 应用程序。当为 apk 导出应用程序时,我遇到以下问题。

问题

[2013-09-26 13:16:53 - Fishing_log] Proguard returned with error code 1. See console
[2013-09-26 13:16:53 - Fishing_log] proguard.ParseException: Value of system property 'init' is undefined in 'string/app_name { <init>' in line 2 of file 'C:\Users\owner\workspace8\Fishing_log\bin\proguard.txt',
[2013-09-26 13:16:53 - Fishing_log]   included from argument number 6
[2013-09-26 13:16:53 - Fishing_log]     at proguard.ConfigurationParser.replaceSystemProperties(ConfigurationParser.java:1153)
[2013-09-26 13:16:53 - Fishing_log]     at proguard.ConfigurationParser.file(ConfigurationParser.java:1113)
[2013-09-26 13:16:53 - Fishing_log]     at proguard.ConfigurationParser.parseIncludeArgument(ConfigurationParser.java:242)
[2013-09-26 13:16:53 - Fishing_log]     at proguard.ConfigurationParser.parse(ConfigurationParser.java:150)
[2013-09-26 13:16:53 - Fishing_log]     at proguard.ProGuard.main(ProGuard.java:476)

我如何解决这个问题?

我在project.propertiesproguard-project.txt中添加了以下代码

项目属性

proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

proguard-project.txt

 -injars lib
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-dontnote
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-dontwarn sun.misc.Unsafe, java.lang.management.ManagementFactory, org.codehaus.jackson.JsonParser, org.json.JSONObject, org.codehaus.jackson.JsonGenerator, org.codehaus.jackson.JsonFactory, com.google.common.collect.MinMaxPriorityQueue
-keep public class * extends android.app.Application
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
   native <methods>;
}
 -keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}
 -keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
 -keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
#Keep the R
-keepclassmembers class **.R$* {
    public static <fields>;
}
4

1 回答 1

0

构建过程让该工具aapt写出一个配置文件proguard.txt,然后将其传递给 ProGuard。但是,当前版本的 aapt 有一个错误——如果我没记错的话,它不处理类名引用字符串定义的 XML 文件(在 中res/values/strings.xml)。暂时,你应该避免这样的字符串定义。

请注意,该文件proguard-project.txt本质上应该是空的,因为大部分配置已经在共享配置文件中指定${sdk.dir}/tools/proguard/proguard-android.txt。构建过程还会自动为您指定所有-injars-outjars-libraryjars

于 2013-10-02T00:21:45.150 回答