【发布时间】:2019-02-06 20:15:19
【问题描述】:
我的 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"
【问题讨论】:
-
尝试使用
"androidx.fragment:fragment:1.0.0"而不是"androidx.fragment:fragment:1.1.0-alpha03"。您也可以尝试将'androidx.appcompat:appcompat:1.0.2'减少到1.0.0。 -
@Timur Gaysin:恭喜您的解决方案!您可以将解决方案作为答案然后接受它。