Duplicate jar (ListenableFuture.class) while migrating to New Place SDK google

﹥>﹥吖頭↗ 提交于 2020-01-12 07:38:11

问题


I am trying to migrate my Autocomplete widget Places SDK Google to the new one using this migration guide. But once I try to generate my release or debug apk start getting the error

Duplicate jar entry [com/google/common/util/concurrent/ListenableFuture.class]

I read couple of stackoverflow questions and other references and found it was caused by duplicate guava (ListenableFuture). App level dependencies are listed below.

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation androidx.appcompat:appcompat:1.1.0-alpha01
implementation 'androidx.mediarouter:mediarouter:1.1.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.libraries.places:places:1.0.0'

implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-safetynet:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.google.android.material:material:1.1.0-alpha03'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.intuit.sdp:sdp-android:1.0.3'
implementation 'com.roughike:bottom-bar:2.3.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.razorpay:checkout:1.4.7'
implementation 'me.relex:circleindicator:1.2.2@aar'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.multidex:multidex-instrumentation:2.0.0'

}

What I have done so far- 1. excluded listenablefuture from places sdk

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

Result was same. Still Duplicate jar entry error for listenablefuture

  1. excluded entire guava from places sdk

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

Result was NO error. But apk installed, when i runing my activity containing the autocomplete widget, it get the below error and app crashes.

Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/base/Preconditions;
   at com.google.android.libraries.places.api.Places.initialize(Unknown Source:5)
   at com.google.android.libraries.places.api.Places.initialize(Unknown Source:1)
   at com.proyujan.proyujan.MapLeadActivity.onCreate(Unknown Source:26)
   at android.app.Activity.performCreate(Activity.java:7372)
   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
   at android.app.ActivityThread.-wrap12(Unknown Source)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
   at android.os.Handler.dispatchMessage(Handler.java:108)
   at android.os.Looper.loop(Looper.java:166)
   at android.app.ActivityThread.main(ActivityThread.java:7425)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
  1. Found the listenablefuture module in my appcompat dependency. Did step 1 and 2 also with appcompat but result was same.

Please help. How to solve this.


回答1:


SOLVED: Finally found a solution. I stated earlier listenable future duplication was found while adding new dependency library for places SDK, duplicate being in the AppCompat library.

I was using the latest AppCompat library and here was the problem. It seems as per google docs, stable version is 1.0.0. So once I revert back everything to the stable version, the problem was solved.

implementation 'androidx.appcompat:appcompat:1.0.0'

And no need of below:

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



回答2:


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'
   }
}



回答3:


Add this dependency to your build:

api 'com.google.guava:guava:28.1-android'



回答4:


The solution didn't work for me, but after I updated to 2.0.0 things get fixed, version 1.0.0 was giving the error, so use:

implementation 'com.google.android.libraries.places:places:2.0.0'


来源:https://stackoverflow.com/questions/54575037/duplicate-jar-listenablefuture-class-while-migrating-to-new-place-sdk-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!