前人未踏の領域へ Androidアプリ開発編

Androidアプリ開発に関する調査メモ置き場。古い記事にはアプリ以外も含まれます。

Duplicate class対応:Google Play Coreライブラリの分割

内容

androidx.navigation関連のライブラリを2.6.0にあげたところDuplicate classエラーが発生した。

> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.google.android.play.core.common.IntentSenderForResultStarter found in modules jetified-core-1.10.3-runtime (com.google.android.play:core:1.10.3) and jetified-core-common-2.0.2-runtime (com.google.android.play:core-common:2.0.2)
     Duplicate class com.google.android.play.core.common.LocalTestingException found in modules jetified-core-1.10.3-runtime (com.google.android.play:core:1.10.3) and jetified-core-common-2.0.2-runtime (com.google.android.play:core-common:2.0.2)
     Duplicate class com.google.android.play.core.common.PlayCoreDialogWrapperActivity found in modules jetified-core-1.10.3-runtime (com.google.android.play:core:1.10.3) and jetified-core-common-2.0.2-runtime (com.google.android.play:core-common:2.0.2)
     Duplicate class com.google.android.play.core.listener.StateUpdatedListener found in modules jetified-core-1.10.3-runtime (com.google.android.play:core:1.10.3) and jetified-core-common-2.0.2-runtime (com.google.android.play:core-common:2.0.2)
     Duplicate class com.google.android.play.core.splitcompat.SplitCompat found in modules jetified-core-1.10.3-runtime (com.google.android.play:core:1.10.3) and jetified-feature-delivery-2.0.1-runtime (com.google.android.play:feature-delivery:2.0.1)
     Duplicate class com.google.android.play.core.splitcompat.SplitCompatApplication found in modules jetified-core-1.10.3-runtime (com.google.android.play:core:1.10.3) and jetified-feature-delivery-2.0.1-runtime (com.google.android.play:feature-delivery:2.0.1)
以下略

依存関係をチェックすると、Google PlayのCoreライブラリが関係していることが判明。Google Playのライブラリはどこかの時点で機能ごとに分割されたらしい。これまで通りにcoreライブラリをそのまま使っていたが、別ライブラリが依存関係を更新した時点で競合が発生する(した)ので注意。

対応

参考ページを確認し、coreライブラリを削除して使っている機能だけ選んで追加する

-    implementation("com.google.android.play:core:1.10.3")
-    implementation("com.google.android.play:core-ktx:1.8.1")
+    implementation("com.google.android.play:feature-delivery-ktx:2.1.0")
+    implementation("com.google.android.play:app-update-ktx:2.1.0")

参考

developer.android.com