Android Merge libs gradle

时间:2019-02-06 20:15:20

标签: android gradle androidx

我的gradle文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1002
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }



}
dependencies {
    api fileTree(include: ['*.jar'], dir: 'libs')
    api 'androidx.appcompat:appcompat:1.0.2'
    api 'androidx.palette:palette:1.0.0'
    api 'androidx.mediarouter:mediarouter:1.0.0'
    api 'androidx.cardview:cardview:1.0.0'
    api 'androidx.legacy:legacy-support-v4:1.0.0'
    api 'androidx.recyclerview:recyclerview:1.0.0'
    api 'androidx.annotation:annotation:1.0.1'
    api 'androidx.percentlayout:percentlayout:1.0.0'
    api "androidx.fragment:fragment:1.1.0-alpha03"
    api 'androidx.preference:preference:1.0.0'



}

在构建应用程序时,出现下一个错误:

 Task :mobile:transformClassesWithMultidexlistForDebug FAILED
AGPBI: {"kind":"error","text":"Program type already present: com.google.common.util.concurrent.ListenableFuture","sources":[{}],"tool":"D8"}

FAILURE: Build failed with an exception.

 What went wrong:
Execution failed for task ':mobile:transformClassesWithMultidexlistForDebug'.
 com.android.build.api.transform.TransformException: Error while generating the main dex list:
  Error while merging dex archives: 
  Program type already present: com.google.common.util.concurrent.ListenableFuture

我发现了错误。库不兼容"androidx.fragment:fragment:1.1.0-alpha03"'androidx.appcompat:appcompat:1.0.2'中的错误。

如何在不删除androidx.fragment依赖关系的情况下解决错误?

UPD。解决方案:

api 'androidx.appcompat:appcompat:1.1.0-alpha01'
api "androidx.fragment:fragment:1.0.0"

1 个答案:

答案 0 :(得分:0)

解决方案:

替换:

api 'androidx.appcompat:appcompat:1.0.2'
api "androidx.fragment:fragment:1.1.0-alpha03"

收件人:

api 'androidx.appcompat:appcompat:1.1.0-alpha01'
api "androidx.fragment:fragment:1.0.0"

希望,AndroidX库将变得更加稳定...