Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 364
Bharat Kumar Avatar asked Feb 07 '19 13:02

Bharat Kumar


2 Answers

Add this dependency to your build:

api 'com.google.guava:guava:28.1-android'
like image 155
Alécio Carvalho Avatar answered Oct 10 '22 03:10

Alécio Carvalho


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'
}
like image 30
Bharat Kumar Avatar answered Oct 10 '22 02:10

Bharat Kumar