0

我正在尝试使用 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
4

2 回答 2

5

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

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

于 2013-03-14T12:25:36.760 回答
0

我最近有这个问题。我的解决方案最终是我只需要清理项目,这导致我出现不同的错误:

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

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

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

于 2013-11-18T22:18:12.260 回答