Fixing Google Services Conflict with Ionic + Firebase

in ionic •  6 years ago 

ionic_firebase_cordova-googleservices.jpg

Official post: https://ionictheme.com/fixing-google-services-conflict-ionic-firebase

Usually often when we implement in our Ionic + Firebase project more than one cordova plugin that integrates with google services, we have some or a lot of issues in the time of build for Android.

For a many times we search fix these problems that cause head pain to solve this, but, often because of cordova-fcm-plugin combined with cordova-googleplus and others.

This post will help you to solve the 2 main issues that frequently happen in the most of cases, only! check bellow my 2 solutions to theses main issues:

First case of Android build fails: FCM + Analytics

:processDebugGoogleServices
Found com.google.firebase:firebase-core:+, but version 9.0.0 is needed for the google-services plugin.
Found com.google.firebase:firebase-messaging:+, but version 9.0.0 is needed for the google-services plugin.
:processDebugGoogleServices FAILED
        
FAILURE: Build failed with an exception.
        
* What went wrong:
Execution failed for task ':processDebugGoogleServices'.
> Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.

If you are using FCM plugin + Analytics plugin, change gradle and the plugins: plugin.xml, here is what i've done:

FCMPlugin.gradle

buildscript {
    repositories {
            jcenter()
            mavenLocal()
        }
    dependencies {
        classpath 'com.android.tools.build:gradle:+'
        classpath 'com.google.gms:google-services:3.1.0'
    }
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin

plugin.xml for the cordova-plugin-fcm

<framework src="com.google.firebase:firebase-core:9.0.0" />
<framework src="com.google.firebase:firebase-messaging:9.0.0" />

plugin.xml for google-analytics

<framework src="com.google.android.gms:play-services-analytics:9.0.0" />

So, i have put the framework source in the same version on both plugins, i guess if you do this it will work.

Second case of Android build fails: FCM + Google Plus or other google services plugin

Found com.google.android.gms:play-services-location:11.+, but version 9.0.0 is needed for the google-services plugin.
Found com.google.android.gms:play-services-auth:11.8.0, but version 9.0.0 is needed for the google-services plugin.
Found com.google.android.gms:play-services-identity:11.8.0, but version 9.0.0 is needed for the google-services plugin.
:processArmv7DebugGoogleServices
FAILED

FAILURE: Build failed with an exception.

What went wrong:
Execution failed for task ':processArmv7DebugGoogleServices'.
Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.

In platforms > android > cordova-plugin-fcm > youapp-FCMPlugin.gradle, remove the lines classpath 'com.google.gms:google-services:3.0.0' and apply plugin: com.google.gms.googleservices.GoogleServicesPlugin

In platforms > android > build.gradle, add classpath 'com.google.gms:google-services:3.2.1' in dependencies (around line 32)

In platforms > android > app > build.gradle, add apply plugin: 'com.google.gms.google-services' at the very end of the file.

If this does not work, change lines 68 and 69 (framework tags) of plugins > cordova-plugin-fcm > plugin.xml to

<framework src="com.google.firebase:firebase-core:11.8.0" /> 
<framework src="com.google.firebase:firebase-messaging:11.8.0" />

remove and add the android platform again and redo the steps above. In 90% of cases these tips are too much effective, that issues e more commom than you all imagine, but, fully repairable.

If you have any more fix solution to suggest, contact us and we'll update this post and improve this steps to get more effectiveness.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!