META-INF/version duplicate error when using Proguard
Asked Answered
G

4

18

Gradle : 4.10.1 Gradle Android Plugin version : 3.3.2 Proguard : 6.0.3 JDK - 1.9 Android Studio 3.3.2 When I try to build apk release version along with Proguard. I get the following error -

Caused by: java.io.IOException: Please correct the above warnings first.
    at proguard.InputReader.execute(InputReader.java:149)
    at proguard.ProGuard.readInput(ProGuard.java:255)
    at proguard.ProGuard.execute(ProGuard.java:96)
    ......

This seems to be caused due to this -

Warning: class [META-INF/versions/9/module-info.class] unexpectedly contains class [module-info]
Note: duplicate definition of program class [module-info]
Note: there were 20 duplicate class definitions.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning: there were 21 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.

From extensive searching it looks like Proguard has a problem with META-INF/versions/9. I have multiple dependencies that contain this.

While the issue to seems to somewhat documented, no solutions prescribed seem to work. https://sourceforge.net/p/proguard/bugs/665/ suggests filtering out those class files via -

-injars my_lib.jar(!META-INF/versions/**.class)

However when I try this it just labels more files as duplicate and incorrectly named. I also tried excluding it via gradle-

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/INDEX.LIST'
        exclude 'META-INF/versions'
        exclude 'META-INF/versions/9/module-info.class'
   }

This also fails to resolve the problem. How do I solve this problem ?

Gainsay answered 10/4, 2019 at 9:20 Comment(4)
I see the same issue with ProGuard 6.0.3, Gradle 5.1 and Java 1.8.0_202.Ranita
The best thing to do now is switch to R8 instead of Proguard.Gainsay
Git any responsePonder
Did you find any solution?Demaggio
C
2

I realise this is a very old question, but I was able to get this to work using this gradle configuration:

task obfuscate(type: proguard.gradle.ProGuardTask) {
    configuration files("proguard-project.txt")
    libraryjars files("build/rt.jar", "build/jce.jar")
    injars files("build/libs/desktop-${version}.jar"), filter: "!META-INF/versions/**/*.class"
    outjars files("build/libs/obfuscated.jar")
}

I think the issue with the injars directive you used might be the path - should be META-INF/versions/**/*.class.

Confederate answered 24/6, 2020 at 20:33 Comment(0)
R
0

Using the option -ignorewarnings in proguard-project.txt 'fixed' it for me, the generated jar works fine as long as the only warnings mentioned by Proguard are related to META-INF.

Romanaromanas answered 24/11, 2019 at 8:3 Comment(2)
This only works until other valid warnings are issued by ProGuard and then ignored. Unless you are 100% certain that everything is processed exactly as you intend it to be you then run the risk of encountering runtime errors.Solorio
This will ignore all warnings coming in futureCartomancy
C
0

I realise this is an old question, but I had issues with this when upgrading some other libs in an application.

I found the <inLibsFilter> tag at the proguard maven plugin page which helped me get it to work. I used it like this (in my <configuration> tag:

            <inLibsFilter>!META-INF/versions/**</inLibsFilter>

Hopefully it can help others that may stumble upon it..

Compo answered 22/4, 2022 at 9:46 Comment(1)
Just realized OP is using gradle and I maven, but there might be a similar configuration setting in gradle...Compo
G
0

Upgrading the Gradle version will solve the issue as proguard version 6.2.1 has filter to prevent such cases https://sourceforge.net/p/proguard/bugs/665/

Grenade answered 7/8, 2023 at 3:52 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Cog

© 2022 - 2024 — McMap. All rights reserved.