Android ProGuard错误与org.xmlpull.v1.XmlPullParser

当我的应用程序与ProGuard一起构build时,会失败并显示以下消息。 我使用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),但有相同的警告。

Solutions Collecting From Web of "Android ProGuard错误与org.xmlpull.v1.XmlPullParser"

将此行添加到proguard-project.txt

 -dontwarn org.xmlpull.v1.** 

和这一行到project.properties

 proguard.config=proguard-project.txt 

我解决了这个使用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 

我还没有通过Eclipse的proguard运行android的解决scheme,但如果你从命令行手动运行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相关的警告。 首先修复错误和其他警告,如果必须, -ignorewarningsproguard.cfg使用-ignorewarnings

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

而且,你有4247个重复的类定义。 这可能是由于你提到的“指定一些图书馆”。 我猜这些库的jar已经包含在构build脚本自动,所以你不应该再指定它们。

我觉得你的jar包包含XmlPullParser类,而android.jar也包含这个。 所以你可以删除jar包中的org.xmlpull.*类,然后重新构build。

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

我删除了:

  minifyEnabled true shrinkResources true 

并返回到原来的设置

 minifyEnabled false