18

当我的应用程序使用 ProGuard 构建时,它会失败并显示以下消息。我使用由 Android SDK 生成的默认 proguard.cfg 和一些 -libraryjars。我能为它做些什么?

[2011-03-17 09:27:04 - MyProject] Proguard returned with error code 1. See console
[2011-03-17 09:27:04 - MyProject] Note: there were 4247 duplicate class definitions.
[2011-03-17 09:27:04 - MyProject] Warning: library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser
[2011-03-17 09:27:04 - MyProject] Warning: library class android.content.Intent depends on program class org.xmlpull.v1.XmlPullParser
[2011-03-17 09:27:04 - MyProject] Warning: library class android.graphics.drawable.AnimationDrawable depends on program class org.xmlpull.v1.XmlPullParser
[2011-03-17 09:27:04 - MyProject] Warning: library class android.graphics.drawable.BitmapDrawable depends on program class org.xmlpull.v1.XmlPullParser
[2011-03-17 09:27:04 - MyProject] Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
[2011-03-17 09:27:04 - MyProject] Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
[2011-03-17 09:27:04 - MyProject] Warning: library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser
[2011-03-17 09:27:04 - MyProject] Warning: library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser
[2011-03-17 09:27:04 - MyProject] Warning: library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser
[2011-03-17 09:27:04 - MyProject]       You should check if you need to specify additional program jars.
[2011-03-17 09:27:04 - MyProject] Warning: there were 9 instances of library classes depending on program classes.
[2011-03-17 09:27:04 - MyProject]          You must avoid such dependencies, since the program classes will
[2011-03-17 09:27:04 - MyProject]          be processed, while the library classes will remain unchanged.
[2011-03-17 09:27:04 - MyProject] java.io.IOException: Please correct the above warnings first.
[2011-03-17 09:27:04 - MyProject]   at proguard.Initializer.execute(Initializer.java:321)
[2011-03-17 09:27:04 - MyProject]   at proguard.ProGuard.initialize(ProGuard.java:211)
[2011-03-17 09:27:04 - MyProject]   at proguard.ProGuard.execute(ProGuard.java:86)
[2011-03-17 09:27:04 - MyProject]   at proguard.ProGuard.main(ProGuard.java:492)

显然,org.xmlpull.v1.XmlPullParser 不是程序类。我已将 ProGuard 更新到最新版本(4.6),但有相同的警告。

4

8 回答 8

25

将此行添加到 proguard-project.txt

-dontwarn org.xmlpull.v1.**

这条线到 project.properties

proguard.config=proguard-project.txt
于 2014-02-11T15:31:10.717 回答
13

我使用 proguard 文件中的设置解决了这个问题:

-dontwarn org.kobjects.**
-dontwarn org.ksoap2.**
-dontwarn org.kxml2.**
-dontwarn org.xmlpull.v1.**

-keep class org.kobjects.** { *; }
-keep class org.ksoap2.** { *; }
-keep class org.kxml2.** { *; }
-keep class org.xmlpull.** { *; }

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontoptimize
-dontpreverify
于 2015-10-22T17:22:46.383 回答
2

我认为你的 jar 包包含XmlPullParser类,而 android.jar 也包含这个。因此,您可以删除org.xmlpull.*jar 包中的类,然后重新构建。

于 2012-05-28T13:09:05.603 回答
2

我还没有通过 eclipse for android 运行 proguard 的解决方案,但是如果您从命令行手动运行 proguard,您可以将以下内容放入您的proguard.cfg

-basedirectory /home/pjv/workspace/collectionista-repo/collectionista-main

-injars /tmp/android_4500371803543847111.jar
-injars libs/joda-time-1.6.jar(!META-INF/MANIFEST.MF)
-injars libs/FlurryAgent.jar(!META-INF/MANIFEST.MF)
-injars libs/veecheck-2.0.jar(!META-INF/MANIFEST.MF)
-injars libs/commons-lang-2.4.jar(!META-INF/MANIFEST.MF,!META-INF/NOTICE.txt,!META-INF/LICENSE.txt)
-injars libs/OIAbout-lib-temporary.jar(!META-INF/MANIFEST.MF)
-injars libs/libGoogleAnalytics.jar(!META-INF/MANIFEST.MF)
-injars libs/xstream-1.3.1.jar(!META-INF/MANIFEST.MF)
-injars libs/ZQL_custom.jar(!META-INF/MANIFEST.MF)
-injars libs/xpp3_min-1.1.4c.jar(!META-INF/MANIFEST.MF)
-injars libs/GoogleAdMobAdsSdk-4.1.0.jar(!META-INF/MANIFEST.MF)
-injars libs/bugsense-trace.jar(!META-INF/MANIFEST.MF)
-outjars /tmp/android_1348923171424559204.jar

-libraryjars /opt/android-sdk/android-sdk-linux_x86-1.6_r1/platforms/android-12/android.jar(!org/xmlpull/v1/XmlPullParser.class,!org/xmlpull/v1/XmlPullParserException.class)

请注意如何XmlPullParser.class从 android API jar 中过滤。

不要担心与XmlPullParser刚刚相关的警告。首先修复错误和其他警告,如果必须,-ignorewarnings请在proguard.cfg.

于 2011-06-14T20:05:09.363 回答
1

根据您提供的部分日志,Android 运行时类 org.xmlpull.v1.XmlPullParser 已在您的程序代码中结束。您应该确保它不存在于bin/classes或lib的某个 jar 中,因为它已经存在于库 jar android.jar 中。

此外,您有 4247 个重复的类定义。这可能是由于您提到的指定“一些-libraryjars”。我猜这些库 jars 已经被构建脚本自动包含了,所以你不应该再次指定它们。

于 2011-03-18T18:01:41.063 回答
0

您的文件夹中已经存在依赖项,

像下面这样排除它:

dependencies {
  configurations {
      all*.exclude group: 'xmlpull', module: 'xmlpull'

  }
}
于 2018-10-08T08:19:30.633 回答
0

有时,当您将其中一个测试库作为常规模块依赖项包含在内时,就会发生这种情况。例如不要这样做:

implementation 'com.android.support.test:runner:1.0.2' //wrong!!

做:

androidTestImplementation 'com.android.support.test:runner:1.0.2' //right (:
于 2018-12-18T14:49:19.067 回答
-9

对我来说,我可以通过删除我之前修改过的 build.gradle 来解决它

我删除了:

     minifyEnabled true

     shrinkResources true

并恢复到原来的设置

minifyEnabled false
于 2017-05-25T12:19:05.350 回答