【问题标题】:Duplicate jar (ListenableFuture.class) while migrating to New Place SDK google迁移到 New Place SDK google 时出现重复的 jar (ListenableFuture.class)
【发布时间】:2019-07-01 16:04:57
【问题描述】:

我正在尝试使用此migration guide 将我的自动完成小部件 Places SDK Google 迁移到新的小部件。但是一旦我尝试生成我的发布或调试 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'
}

结果是一样的。仍然为可听的未来重复 jar 条目错误

  1. 从places sdk中排除整个番石榴

    实现('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)
  1. 在我的 appcompat 依赖项中找到了 listenablefuture 模块。第 1 步和第 2 步也使用 appcompat,但结果相同。

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

【问题讨论】:

    标签: android google-places-api


    【解决方案1】:

    新的地方 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'
       }
    }
    

    【讨论】:

      【解决方案2】:

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

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

      implementation 'androidx.appcompat:appcompat:1.0.0'
      

      并且不需要下面的:

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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          【解决方案4】:

          将此依赖项添加到您的构建中:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2020-05-05
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-11-26
            • 2014-11-30
            • 2017-06-01
            • 1970-01-01
            相关资源
            最近更新 更多