Android:proguard 中的重复类错误

标签 android gradle proguard

在编译我的应用程序时,出现以下错误(敏感的路径 fragment 已被删除)

Execution failed for task ':app:proguardDebug'.
> java.io.IOException: Can't write [/projects/app/build/intermediates/classes-proguard/debug/classes.jar] (Can't read [/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.4/4216af16d38465bbab0f3dff8efa14204f7a399a/commons-codec-1.4.jar(;;;;;;!META-INF/MANIFEST.MF)] (Duplicate zip entry [commons-codec-1.4.jar:org/apache/commons/codec/binary/Base64.class]))

这向我表明,编译器在两个地方看到了应用程序尝试使用 commons.codec.binary.Base64.class 作为依赖项的地方。我已经检查并再次检查了我的库,但只有一个库(Amazon AWS)正在尝试使用它。

在此错误之上,我收到了一些其他警告,这些警告也对我发出了危险信号:

Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-lang3-3.1.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [commons-lang3-3.1.jar:META-INF/NOTICE.txt])
Warning:can't write resource [META-INF/LICENSE.txt] (Duplicate zip entry [commons-codec-1.4.jar:META-INF/LICENSE.txt])
Warning:can't write resource [META-INF/NOTICE.txt] (Duplicate zip entry [commons-codec-1.4.jar:META-INF/NOTICE.txt])

我根本没有在我的应用程序中明确使用 commons-codec-1.4 或 commons-lang3-3.1,以为我曾经使用 lang3 后来删除它。为什么这些在编译日志中被引用?我的 Maven 库之一可以使用它们吗?我将在我的 gradle 文件中包含下面的 Maven 库列表。

这是我的 proguard 和 gradle 文件供引用:

PROGUARD

-keep class org.w3c.dom.bootstrap.** { *; }
-keep class org.joda.time.** { *; }
-keep class com.facebook.** { *; }
-keep class org.apache.commons.** { *; }
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-dontwarn org.codehaus.jackson.map.ext.**
-dontwarn oauth.**
-dontwarn com.amazonaws.**
-dontwarn org.joda.time.**
-dontwarn org.apache.commons.codec.**
-dontwarn com.fasterxml.jackson.databind.ext.**

渐变

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'

    defaultConfig {
        applicationId 'com.my.package'
        minSdkVersion 14
        targetSdkVersion 20
        versionCode 9
        versionName '1.2'
    }

    buildTypes {
        release {
            debuggable false
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            debuggable true
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    lintOptions {
        checkReleaseBuilds false
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/MANIFEST.MF'
    }
}

dependencies {
    compile fileTree(dir: 'libs',  include: ['*.jar'])

    //noinspection GradleDependency
    compile 'com.google.android.gms:play-services:5.0.89'

    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
    compile 'se.emilsjolander:stickylistheaders:2.5.0'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
    compile project(':facebook')
    compile 'com.tumblr:jumblr:0.0.10'
    compile 'com.android.support:support-v4:20.0.0'
}

我最好的猜测是这些库中的一个或多个正在使用 apache lang3 和编解码器作为它们自己的依赖项,这会导致在我编译应用程序时发生冲突。只有当我将亚马逊作为必需的 jar 包含时才会出现此问题,所以我知道这在某种程度上是罪魁祸首,但我不知道还有什么与之冲突。

我阅读了一些有关将 -injars 与混淆器一起使用的内容,但根据他们的文档,Android 不需要您使用它。

任何建议将不胜感激,谢谢!

最佳答案

我不确定这是否对您有帮助,但我会在此处发布我的答案以防其他人觉得这有用。我的问题是我的依赖项声明中有 2 个引用。我使用的是 Universal Image Loader 库,我的语句如下所示:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.android.support:support-v4:22.1.1'
    compile 'uk.co.chrisjenx:calligraphy:2.0.2'
    /* UIL was the failing reference */
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
    compile 'com.google.android.gms:play-services:7.3.0'
}

我意识到这个问题(在脑袋一撞之后)是我已经通过 libs 文件夹引用了 UIL(即它已经被语句 compile fileTree( dir: 'libs', include: ['*.jar'])。所以它通过 libs 编译一次,然后通过显式调用编译对 UIL 的引用。我删除了显式调用并清除了错误。也许您正在调用 libs 目录中的某些内容,该目录还包含对有问题的库的引用,然后当它尝试编译 AWS 服务时它已经有一个版本公共(public)图书馆和呕吐物。

关于Android:proguard 中的重复类错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25676755/

相关文章:

java - 我应该把 META-INF 放在 Gradle 的什么地方?

java - Proguard android找不到引用的类

android - ListView 的自定义基础适配器

java - 将用户选择的日期从 DatePicker 设置为 Calendar

c++ - 如何从应用程序子项目中的gradle子项目链接静态库

java - 如何让 ProGuard Maven 插件使用最新的 ProGuard 版本?

android - 混淆我的项目时如何保留人行横道代码?

android - 如何在android中长按自定义 ListView 删除项目?

android - 如何在android xml中绘制三角形

java - AAPT:错误:找不到属性 android:clipToOutline