22

When my application is build with ProGuard, it fails with following message. I use a default proguard.cfg generated by Android SDK with some -libraryjars. What can I do for it?

[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)

Apparently, org.xmlpull.v1.XmlPullParser is not a program class. I've updated ProGuard to newest version(4.6), but have same warnings.

Nuree Son
  • 221
  • 1
  • 2
  • 3

8 Answers8

27

add this line to proguard-project.txt

-dontwarn org.xmlpull.v1.**

and this line to project.properties

proguard.config=proguard-project.txt
Medo Elkamaly
  • 2,508
  • 1
  • 20
  • 15
  • 4
    I am not able to find proguard-project.txt and project.properties. I have two .properties files:- 1. local.properties 2. gradle.properties . proguard-rules.pro file is available inside app module – Harish Gyanani Dec 14 '16 at 06:02
  • Thanks a lot for the answer. In my case I have to use both your answer and -keep class org.xmlpull.v1.** { *; } – Hong Sep 27 '17 at 15:43
  • App still crashes when this line is added – Mladen Rakonjac Oct 03 '18 at 15:37
  • Related discussion in Google issue tracker : https://issuetracker.google.com/issues/247066506 – Reejesh Apr 24 '23 at 09:15
  • 2
    I had to additionally add `-dontwarn android.content.res.**` to proguard to take a release aab. – Reejesh Apr 25 '23 at 03:31
  • None of the answers here helped me regarding this issue. This is what worked for me, the combination of the two below: 1. Under app gradle file: configurations { all { exclude group: 'xml-apis' } } 2. In the proguard file: -dontwarn org.slf4j.** – bogdan May 08 '23 at 07:09
15

I solved this using this settings in the proguard file:

-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
Ton
  • 9,235
  • 15
  • 59
  • 103
2

I think your jar package include XmlPullParser class, and android.jar also include this. So you can remove org.xmlpull.* classes in the jar package, and build again.

Botz3000
  • 39,020
  • 8
  • 103
  • 127
LeOnLee
  • 41
  • 4
  • Could you elborate on what this means? And possibly how to do it. What do you mean by "jar package"? – Mafro34 Dec 04 '13 at 13:27
  • how to remove it? implementation('com.thoughtworks.xstream:xstream:1.4.10-java7') { exclude(group: "xmlpull") } does not work – Mladen Rakonjac Oct 03 '18 at 18:18
  • 1
    implementation ("com.squareup.retrofit2:converter-simplexml:2.6.0") { exclude module: "simple-xml" } – Jan Rabe Jun 29 '19 at 00:48
2

I don't have the solution yet for proguard run via eclipse for android, but if you run proguard manually from the command line, you can put the following in your 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)

Note how XmlPullParser.class is filtered from the android API jar.

Don't worry about the warnings related to XmlPullParser just yet. Fix the errors and other warnings first, and if you must, use -ignorewarnings in your proguard.cfg.

pjv
  • 10,658
  • 6
  • 43
  • 60
  • In the mean time I moved on to something more elegant. See http://stackoverflow.com/questions/6780902/problem-with-proguard-and-xmlpullparser/7986229 – pjv Nov 02 '11 at 19:34
1

According to the partial log that you provide, the Android runtime class org.xmlpull.v1.XmlPullParser has ended up in your program code. You should make sure it is not present in bin/classes or in some jar in lib, because it is already present in the library jar android.jar.

Furthermore, you have 4247 duplicate class definitions. This is probably due to specifying "some -libraryjars" as you mention. I'm guessing these library jars are already included automatically by the build script, so you shouldn't specify them again.

Eric Lafortune
  • 45,150
  • 8
  • 114
  • 106
  • Eric, the reason he (or in any case, I) has the XmlPullParser class in a jar in his libs is so that it would override the Android built-in XmlPullParser class which is deficient for some uses. Due to the way we formulate the proguard.cfg on Android it's not possible to filter out the built-in one, neither do we want to filter out the better one, AFAIK. It also doesn't seem wise to roll our own Android jars, if that is even possible. How should we deal with this?? Thanks – pjv Jun 13 '11 at 18:12
  • 2
    If your program jars contain better implementations, you really should try to filter out the library versions, with "-libraryjars android.jar(!org/xmlpull/v1/**)", so ProGuard gets clean input. If that's not possible, you can specify something like "-dontwarn org.xmlpull.v1.**". It should work in this case, because ProGuard gives program classes precedence over library classes. – Eric Lafortune Jun 15 '11 at 22:33
0

Sometimes it happens when you include one of your test libraries as a regular module dependency. For example don't do:

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

do:

androidTestImplementation 'com.android.support.test:runner:1.0.2' //right (:
yshahak
  • 4,996
  • 1
  • 31
  • 37
-1

The dependency already exist on your folder,

exclude it like below:

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

  }
}
Dylan Breugne
  • 455
  • 4
  • 7
-9

for me I could solve it by removing my previous modified build.gradle

I removed:

     minifyEnabled true

     shrinkResources true

and returned to the original setting

minifyEnabled false
OsamaHamed
  • 79
  • 6