8

由于以下错误,我当前的 Android 项目现在将无法构建

AGPBI: {"kind":"error","text":"Program type already present: com.google.common.util.concurrent.ListenableFuture","sources":[{}],"tool":"D8"}
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /Users/....
Program type already present: com.google.common.util.concurrent.ListenableFuture

我正在使用 Android Studio 版本

Android Studio 3.2
Build #AI-181.5540.7.32.5014246, built on September 17, 2018
JRE: 1.8.0_152-release-1136-b06 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.11.6

以下链接没有帮助

Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.

我为触发此错误所做的更改如下:-

将我的 tarke sdk 版本等从 27 增加到 28

   compileSdkVersion = 28
   targetSdkVersion = 28
   minSdkVersion = 21
   buildToolsVersion = "28.0.2"
   supportLibVersion = "28.0.0"

将我的 kotlin 版本增加到ext.kotlin_version = '1.2.61'

并切换到 gradle 3.2.0

 classpath 'com.android.tools.build:gradle:3.2.0'

如何修复我的 gradle 构建?

更新

跑过./gradlew app:dependencies

我发现了这个

+--- android.arch.work:work-runtime:1.0.0-alpha09
|    +--- android.arch.lifecycle:extensions:1.1.0 -> 1.1.1 (*)
|    +--- androidx.concurrent:futures:1.0.0-alpha01
|    |    +--- com.google.guava:listenablefuture:1.0
|    |    \--- androidx.annotation:annotation:1.0.0-rc01
|    \--- android.arch.persistence.room:runtime:1.1.1-rc1
|         +--- android.arch.persistence.room:common:1.1.1-rc1
|         |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|         +--- android.arch.persistence:db-framework:1.1.1-rc1
|         |    +--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|         |    \--- android.arch.persistence:db:1.1.1-rc1
|         |         \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|         +--- android.arch.persistence:db:1.1.1-rc1 (*)
|         +--- android.arch.core:runtime:1.1.1 (*)
|         \--- com.android.support:support-core-utils:26.1.0 -> 28.0.0 (*)

因此我补充说

api ("android.arch.work:work-runtime:$archWorkerRuntimeVersion") {
        exclude group: 'com.google.guava', module: 'listenablefuture'
    }

到我的 gradle 构建

这导致

More than one file was found with OS independent path 'META-INF/proguard/androidx-annotations.pro'

因此我添加了

packagingOptions {
        exclude 'META-INF/proguard/androidx-annotations.pro'
    }

现在我的构建完成了

增加安卓版本真的要这么难吗?

4

0 回答 0