Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Google Services to Cordova Android app using Gradle

I'm trying to integrate Google Analytics into my Cordova Android app. I have used guide from https://developers.google.com/analytics/devguides/collection/android/v4/, but when i want to add

apply plugin:'com.google.gms.google-services'

into build.gradle it throws error:

A problem occurred evaluating root project 'android'.
Failed to apply plugin [id 'com.google.gms.google-services']
Plugin with id 'com.google.gms.google-services' not found.
like image 296
Michael Dudek Avatar asked Nov 25 '25 02:11

Michael Dudek


1 Answers

I finally found a solution:

1) I had to setup plugin.xml to use custom ga.gradle file for build

 <platform name="android">
         <framework src="src/android/ga.gradle" custom="true" type="gradleReference" />
         <framework src="com.google.android.gms:play-services-analytics:8.1.0"/>
         <resource-file src="src/android/google-services.json" target="google-services.json" />
           ...
     </platform>

2) Create ga.gradle file

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.google.gms:google-services:1.4.0-beta6'
    }
}

// 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
like image 185
Michael Dudek Avatar answered Nov 26 '25 14:11

Michael Dudek