尝试配置用于混淆的proguard时出现异常。重复的类定义

时间:2013-03-11 14:15:10

标签: android security proguard

我正在尝试使用proguard来混淆我的代码。我在我的项目中使用谷歌地图。

但我得到以下例外情况。

如何解决?

        Proguard returned with error code 1. See console
    Warning: class [bin/classes/com/google/android/gms/BuildConfig.class] unexpectedly contains class [com.google.android.gms.BuildConfig]
    Warning: class [bin/classes/com/google/android/gms/R$attr.class] unexpectedly contains class [com.google.android.gms.R$attr]
    Warning: class [bin/classes/com/google/android/gms/R$id.class] unexpectedly contains class [com.google.android.gms.R$id]
    Warning: class [bin/classes/com/google/android/gms/R$string.class] unexpectedly contains class [com.google.android.gms.R$string]
    Warning: class [bin/classes/com/google/android/gms/R$styleable.class] unexpectedly contains class [com.google.android.gms.R$styleable]
    Warning: class [bin/classes/com/google/android/gms/R.class] unexpectedly contains class [com.google.android.gms.R]
    Note: there were 1656 duplicate class definitions.
    Warning: there were 6 classes in incorrectly named files.
             You should make sure all file names correspond to their class names.
             The directory hierarchies must correspond to the package hierarchies.
             If you don't mind the mentioned classes not being written out,
             you could try your luck using the '-ignorewarnings' option.
    java.io.IOException: Please correct the above warnings first.
        at proguard.InputReader.execute(InputReader.java:133)
        at proguard.ProGuard.readInput(ProGuard.java:196)
        at proguard.ProGuard.execute(ProGuard.java:78)
        at proguard.ProGuard.main(ProGuard.java:492)
    Proguard returned with error code 1. See console
    proguard.ParseException: Unexpected keyword 'names' in line 30 of file 'D:\redBus_Update_3\proguard-project.txt',
      included from argument number 4
        at proguard.ConfigurationParser.unknownAccessFlag(ConfigurationParser.java:1048)
        at proguard.ConfigurationParser.parseClassSpecificationArguments(ConfigurationParser.java:547)
        at proguard.ConfigurationParser.parseKeepClassSpecificationArguments(ConfigurationParser.java:490)
        at proguard.ConfigurationParser.parse(ConfigurationParser.java:138)
        at proguard.ProGuard.main(ProGuard.java:484)

请在下面找到proguard文件的内容。

我也试过对这些文件使用忽略警告选项

    # To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-libraryjars D:\google-play-services_lib_en
-libraryjars D:\redBus_Update_3\libs\FlurryAgent.jar
-libraryjars D:\redBus_Update_3\libs\gson-2.2.2.jar
-libraryjars D:\redBus_Update_3\libs\bugsense-3.0.1.jar
-libraryjars D:\redBus_Update_3\libs\android-support-v4.jar

-keep class android.location.** { *; }

-keep public class com.google.android.maps.** {*;}
-keep public class com.google.android.maps.** {*;}
-keep public class com.google.android.gms.maps.** {*;}

-dontwarn com.google.android.maps.GeoPoint
-dontwarn com.google.android.maps.MapActivity
-dontwarn com.google.android.maps.MapView
-dontwarn com.google.android.maps.MapController 
-dontwarn com.google.android.maps.Overlay

2 个答案:

答案 0 :(得分:5)

您不应在proguard-project.txt中指定任何-libraryjars选项。标准构建脚本会自动将它可以在libs目录中找到的库传递给ProGuard。

如果您收到有关缺少类的任何警告,即使应用程序在调试模式下正常工作,您也应该考虑为这些类添加-dontwarn选项(参见本网站上的许多相关问题和答案)。

答案 1 :(得分:0)

我最近遇到过这个问题。我的解决方案最终是因为我只需要清理项目,这导致了一个不同的错误:

/gen already exists but is not a source folder. Convert to a source folder or rename it.

所以我将它重命名为genX,然后自动重新创建,清理项目,测试它,然后删除genX。

这样做解决了我的Proguard问题。