android guava ListenableFuture dependency resolution errors

com.google.guava的guava和listenablefuture 的library都引用了ListenableFuture,屬於Duplicate class 的衝突。

Android Studio 裡建議的解法:
https://developer.android.com/studio/build/dependencies#resolution_errors

網友建議解法:

new places SDK is working but when you migrate to android x it’s not working

so add these below lines in app/build dependencies

dependencies {
    implementation ('com.google.android.libraries.places:places:1.0.0'){
        exclude group: 'com.google.guava', module: 'listenablefuture'
    }
}

android {
   configurations{
       all*.exclude group: 'com.google.guava', module: 'listenablefuture'
   }
}

Max 個人,是增加上面那段 android { } 到 dependencies { } 下方,就解決了。

解决方案2:

module内,找到build.gradle,在android{}内增加configurations,如下:

android {
    ......
    configurations {
        all*.exclude group: 'com.google.guava', module: 'listenablefuture'
        all*.exclude group: 'com.google.guava', module: 'guava'
    }
    ......
}

資料來源:

Duplicate jar (ListenableFuture.class) while migrating to New Place SDK google
https://stackoverflow.com/questions/54575037/duplicate-jar-listenablefuture-class-while-migrating-to-new-place-sdk-google

Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules guava-20.0.jar (com.google.guava:guava:20.0)
https://stackoverflow.com/questions/56639529/duplicate-class-com-google-common-util-concurrent-listenablefuture-found-in-modu

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *