Android 迁移到新位置时复制jar(ListenableFuture.class)

Android 迁移到新位置时复制jar(ListenableFuture.class),android,google-places-api,Android,Google Places Api,我正在尝试使用这个工具将我的自动完成widget Places SDK Google迁移到新的widget。但是,一旦我尝试生成我的发布或调试apk,就会出现错误 Duplicate jar entry [com/google/common/util/concurrent/ListenableFuture.class] 我读了几个stackoverflow问题和其他参考资料,发现它是由重复的番石榴(ListenableFuture)引起的。下面列出了应用程序级依赖项 dependencies

我正在尝试使用这个工具将我的自动完成widget Places SDK Google迁移到新的widget。但是,一旦我尝试生成我的发布或调试apk,就会出现错误

Duplicate jar entry [com/google/common/util/concurrent/ListenableFuture.class]
我读了几个stackoverflow问题和其他参考资料,发现它是由重复的番石榴(ListenableFuture)引起的。下面列出了应用程序级依赖项

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

到目前为止我做了什么- 1.已从places sdk中排除listenablefuture

implementation ('com.google.android.libraries.places:places:1.0.0'){
    exclude group: 'com.google.guava', module: 'listenablefuture'
}
结果相同。listenablefuture仍然存在重复的jar条目错误

  • 不包括所有的番石榴

    implementation ('com.google.android.libraries.places:places:1.0.0'){
        exclude group: 'com.google.guava', module: 'listenablefuture'
    }
    
    实现('com.google.android.libraries.places:places:1.0.0'){ 排除组:“com.google.guava” }

  • 结果没有错误。但是安装了apk,当我运行包含自动完成小部件的活动时,它会出现以下错误,应用程序崩溃

    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)
    
  • 在我的appcompat依赖项中找到listenablefuture模块。同样使用appcompat执行步骤1和2,但结果相同

  • 请帮忙。如何解决这个问题。

    新地方SDK正在运行,但当您迁移到android x时,它就不工作了

    因此,在应用程序/构建依赖项中添加以下行

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

    解决:终于找到了解决方案。我之前说过,在为PlacesSDK添加新的依赖项库时发现了可侦听的未来复制,复制项位于AppCompat库中

    我使用的是最新的AppCompat库,问题出在这里。根据谷歌文档,它似乎是1.0.0。因此,一旦我将所有内容恢复到稳定版本,问题就解决了

    implementation 'androidx.appcompat:appcompat:1.0.0'
    
    无需提供以下信息:

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

    该解决方案对我不起作用,但在我更新到2.0.0之后,问题得到了解决,版本1.0.0给出了错误,因此请使用:

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

    将此依赖项添加到生成中:

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

    配置{all*.exclude…已经足够了,因为我已经在上面进行了更新…我相信它覆盖了添加的每个依赖项…但是如果我需要listenablefuture为workmanager等做些什么呢?在我的情况下,仅此而已:配置{all*.exclude组:'com.google.guava',模块:'listenablefuture'helpedI将我的项目升级到androidX,并添加了
    configurations{all*.exclude group:'com.google.guava',module:'listenablefuture'}
    only,并且它在我唯一的帮助中工作良好:configurations{all*.exclude group:'com.google.guava',module:'listenablefuture'}就像@MrVasilev的情况一样,这个额外的配置在没有任何其他功能的情况下为我解决了这个问题。我相信这有点“黑客”直到番石榴和androidx库同步。谢谢@alécio carvalho这对我有帮助,尽管从这个答案中产生了一个问题,为什么它起作用?你能解释一下吗,因为我不明白为什么它起作用@SakshamKhurana,我找到了为什么它起作用。番石榴28.1取决于listanablefuture(LF)的v9999但是这个依赖项是空的。因此,如果你只有LF 1.0可以拉类,那么你就没事了。你之前有LF 1.0和番石榴吗?因为它们都包含类。LF1.0+番石榴28.1(带来空LF 9999)会再次产生单个LF类。参见POM: