32
28

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Google Play servicesとFirebaseの依存コンフリクト解決

Posted at

Google Play servicesとFirebaseは今年の5月からSemVerに移行しました1。それで早速困ったプロジェクトがあったので、「とりあえず全部最新版にアップグレードするだろう常考」以外の手段を提示したいと思います。

エラーの内容

今回問題になった設定は、Google Play servicesとFirebaseに対し下記のようなdependenciesとなっています:

dependencies {
    ...
    implementation 'com.google.firebase:firebase-core:15.0.2'
    implementation 'com.google.firebase:firebase-messaging:15.0.2'
    implementation 'com.google.android.gms:play-services-analytics:16.0.1'
}
buildscript {
    ...
    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.0.1'    
    }
}

上記の設定でGradle Syncすると、下記のエラーが出ます:

The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.2,15.0.2], [16.0.0,16.0.0]], but resolves to 16.0.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

./gradlew :app:dependencies でコンフリクト箇所を確認

まず、エラー内容の指示通りにapply plugin: 'com.google.gms.google-services'をコメントアウトし、コマンドラインで./gradlew :app:dependenciesの結果を確認します:

+--- com.google.firebase:firebase-core:15.0.2
|    +--- com.google.firebase:firebase-analytics:[15.0.2,16.0.0) -> 15.0.2
|    |    +--- com.google.android.gms:play-services-basement:[15.0.1,16.0.0) -> 15.0.1
|    |    |    \--- com.android.support:support-v4:26.1.0 (*)
|    |    +--- com.google.android.gms:play-services-measurement-base:[15.0.2] -> 16.0.0
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
               コンフリクト
...
+--- com.google.android.gms:play-services-analytics:16.0.1
|    +--- com.google.android.gms:play-services-analytics-impl:[16.0.1] -> 16.0.1
|    |    +--- com.google.android.gms:play-services-ads-identifier:15.0.1 (*)
|    |    +--- com.google.android.gms:play-services-base:15.0.1 (*)
|    |    +--- com.google.android.gms:play-services-basement:15.0.1 (*)
|    |    +--- com.google.android.gms:play-services-measurement-base:[16.0.0] -> 16.0.0
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
               play-services-measurement-baseの16.0.0を要求する元凶

つまり、

  • com.google.firebase:firebase-coreを上げるか
  • com.google.android.gms:play-services-analyticsを下げるか

のどちらかを取れば解決するかもしれません。

実際、firebase-coreを上げると今度はcom.google.firebase:firebase-iidのバージョン依存でコンフリクトが発生します。上記と同じ方法で見ると原因はfirebase-messagingのバージョンだと分かります。

最終的に解決策は下記の2パターンになります:

  • com.google.firebase:firebase-core16.0.1com.google.firebase:firebase-messaging17.0.0に上げる
  • com.google.android.gms:play-services-analytics15.0.2に下げる
  1. Release Notes  |  Google APIs for Android  |  Google Developers

32
28
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
28

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?