使用Proguard时出现META-INF /版本重复错误

时间:2019-04-10 09:20:31

标签: android android-gradle proguard meta-inf

等级:4.10.1 Gradle Android插件版本:3.3.2 Proguard:6.0.3 JDK-1.9 Android Studio 3.3.2 当我尝试与Proguard一起构建apk发行版时。我收到以下错误-

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

这似乎是由于此引起的-

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.

从广泛的搜索看来,Proguard的META-INF / versions / 9似乎有问题。我有多个包含此的依赖项。

虽然似乎已对该问题进行了记录,但没有规定的解决方案似乎有效。 https://sourceforge.net/p/proguard/bugs/665/ 建议通过-

过滤掉这些类文件
-injars my_lib.jar(!META-INF/versions/**.class)

但是,当我尝试此操作时,它只会将更多文件标记为重复文件并命名错误。我还尝试通过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'
   }

这也无法解决问题。我该如何解决这个问题?

3 个答案:

答案 0 :(得分:0)

使用proguard-project.txt中的-ignorewarnings选项为我“修复”了它,只要Proguard提到的唯一警告与META-INF有关,生成的jar就可以正常工作。

答案 1 :(得分:0)

我意识到这是一个非常老的问题,但是我可以使用以下gradle配置使它起作用:

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")
}

我认为您使用的injars指令的问题可能是路径-应该为META-INF/versions/**/*.class

答案 2 :(得分:-1)

添加这个 build.gradle 文件

 buildTypes {
    release {
         minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
     }
  }