如何在eclipse中使用proguard来混淆android项目?

时间:2013-09-26 08:04:08

标签: android proguard

如何使用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.properties proguard-project.txt

中添加了以下代码

project.properties

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>;
}

1 个答案:

答案 0 :(得分:0)

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

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