22

I followed google documentation to integrate my app to Google Analytics. But when adding

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

and building my app, I encountered this error:

Error:(49, 0) For input string: "+"

These are the settings I used in the build.gradle of my application:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "com.myapp.xyz"
        manifestPlaceholders = [
            manifestApplicationId : "${applicationId}",
            onesignal_app_id : "ccd48c54-2069-41f9-8ff7-54c7a12f2d18a",
            onesignal_google_project_number: "306632981237"
        ]
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
            'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    // compile 'com.android.support:appcompat-v7:22.2.1'
    compile project(':facebook')
    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:palette-v7:22.2.1'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.onesignal:OneSignal:1.+@aar'
    compile 'com.google.android.gms:play-services-gcm:+'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.google.android.gms:play-services-analytics:8.4.0'
}
apply plugin: 'com.google.gms.google-services'

These are the setting in build.gradle application:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'com.google.gms:google-services:2.0.0-alpha6'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
Mina Farid
  • 5,041
  • 4
  • 39
  • 46

10 Answers10

18

At first you should call

    dependencies {
    classpath 'com.android.tools.build:gradle:1.5.0'
    classpath 'com.google.gms:google-services:2.0.0-alpha2'
}

Don't (Avoid calling +)

compile 'com.google.android.gms:play-services-gcm:+'

Do

compile 'com.google.android.gms:play-services:8.4.0'
Nilabja
  • 4,206
  • 5
  • 27
  • 45
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
17

Need to enter the following entry in both gradle:

  1. Add the following to the @project level gradle file:

    classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.google.gms:google-services:3.0.0'
    
  2. Add the following to the @app level gradle file:

    // Dependency for Google Sign-In
    compile 'com.google.android.gms:play-services-auth:9.4.0'
    
  3. Add plugin:

    apply plugin: 'com.google.gms.google-services'
    
m00am
  • 5,910
  • 11
  • 53
  • 69
rakendu
  • 171
  • 1
  • 2
  • 1
    I'm working with ionic/cordova. Can you explain what is meant about project level and app level my build.gradle is at myApp/platforms/android/build.gradle. But there is also build.gradle at myApp/platforms/android/CordovaLib/build.gradle – Brad W Nov 09 '16 at 19:07
3

Add the following to the @project level gradle file:

    classpath 'com.android.tools.build:gradle:2.3.0'
    classpath 'com.google.gms:google-services:3.0.0'
Sabextc10
  • 51
  • 4
2

Replace the line compile 'com.google.android.gms:play-services-gcm:+'

with the following compile 'com.google.android.gms:play-services-gcm:8.4.0'

in the application build.gradle file.

jaolstad
  • 566
  • 7
  • 20
2

As many ppl said, I've added "classpath 'com.google.gms:google-services:3.0.0'" in the project level gradle.

But, I encountered another error saying "File google-services.json is missing from module root folder.". Eventually, I needed to set up a project via the following link. https://developers.google.com/mobile/add?platform=android

After setting up a project and it took me to go to Firebase console. In that page, I was able to download google-service.json file which was essential to solve this issue.

Drag and drop that JSON file under your project's '/app' folder.

It took me an hour to figure it out. I hope it's helpful for someone.

Minji Song
  • 91
  • 1
  • 3
0

I was having this exact issue, and the following fixed it.. go to platforms>android>project.properties and edit the lines

cordova.system.library.5=com.google.android.gms:play-services-auth:+
cordova.system.library.6=com.google.android.gms:play-services-identity:+

to

cordova.system.library.5=com.google.android.gms:play-services-auth:11.0.1
cordova.system.library.6=com.google.android.gms:play-services-identity:11.0.1

It is said that # Do not modify this file -- YOUR CHANGES WILL BE ERASED! But this fixed my issue

Ninoop p george
  • 678
  • 5
  • 22
0

Change following code in project.properties from:

cordova.system.library.2=com.google.android.gms:play-services-gcm:+
cordova.system.library.3=com.google.android.gms:play-services-location:+

to

cordova.system.library.2=com.google.android.gms:play-services-gcm:11.0.1
cordova.system.library.3=com.google.android.gms:play-services-location:11.0.1

and add google-service.json file to app module

Charles
  • 1,121
  • 19
  • 30
faizi
  • 29
  • 1
  • 3
0

Sometimes, you have to update your REALM-PLUGIN and you need to write this in Top-Level Gradle (Project:Gradle), copy paste below "classpath" line:

buildscript {
  ... 
  dependencies {
    classpath 'io.realm:realm-gradle-plugin:7.0.0' //<--Your answer.
  }
}
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
canerkaseler
  • 6,204
  • 45
  • 38
0

You put line apply plugin: 'com.google.gms.google-services' twice in line 0 and line 49 simply remove one line

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/29844477) – Subhashis Pandey Sep 17 '21 at 07:19
0

"Please take note that the classpath has been updated. The new classpath entry is 'com.google.gms:google-services:4.3.15'