【问题标题】:Duplicate class in two offcial android libs, gradle fails两个官方 android 库中的重复类,gradle 失败
【发布时间】:2015-11-26 10:21:06
【问题描述】:

我正在使用一个需要激活渲染脚本支持模式的库。像这样

defaultConfig {

 minSdkVersion 14
 targetSdkVersion 23
 renderscriptTargetApi 20
 renderscriptSupportModeEnabled true
}

但是当我尝试运行应用程序时,我有这个:

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: android/support/annotation 
/Keep.class

Keep.class 位于 annotation-support lib 和 rendserscript lib 中,都来自 Google,所以我不知道该怎么做。

【问题讨论】:

    标签: android annotations android-gradle-plugin render libs


    【解决方案1】:

    我对我的 build.gradle 文件进行了以下修改,它现在可以工作了:

    renderScriptTargetApi 23

    并添加

    configurations { all*.exclude group: 'com.android.support', module: 'support-annotations' }

    我相信是第二行成功了。

    【讨论】:

    • 我知道这可能有效,不包括库,但我不能丢失支持注释。还是谢谢。
    【解决方案2】:

    此错误仅发生在最新 (23) SDK 版本中。能否尝试将构建版本更改为 22 或 21,同时更改依赖项。

    例如

    android {
           compileSdkVersion 21
            buildToolsVersion "21.1.2"
    }
    dependencies {
    
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:21.0.3'
        compile 'com.android.support:support-v4:21.0.3'  
    }
    

    【讨论】:

    • 在谷歌修复它之前,这似乎是唯一的选择。谢谢。
    • 不确定这是否是目前最好的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    • 2021-11-17
    • 2020-01-14
    • 1970-01-01
    • 2015-11-02
    相关资源
    最近更新 更多