Gradle sync failed: For input string: “+”

2019-04-16 11:44发布

问题:

I want to add Firebase SDK to my Android project.

I added

buildscript {
  dependencies {
    // Add this line
    classpath 'com.google.gms:google-services:3.1.0'
  }
}

to project level gradle file.

Then I added

// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'

Gradle asks for sync. And I get the following error:

12:35   Gradle sync failed: For input string: "+"
            Consult IDE log for more details (Help | Show Log)

How can I fix that? What is wrong?

回答1:

Remove + sign from both dependencies. The + operator is not allowed as its own

Try using the specific version:

com.google.android.gms:play-services-maps:11.0.1
com.google.android.gms:play-services-location:11.0.1

Or

com.google.android.gms:play-services-maps:11.0.+
com.google.android.gms:play-services-location:11.0.+

Which will fetch the most recent version of 11.0 release



回答2:

+ is not recommended, better specify exact version.



回答3:

com.google.android.gms:play-services-maps:+ is not allowed. You can do following:

com.google.android.gms:play-services-maps:11.0.+

Where 11.0.1 is the latest available version of the library included. And 11.0.+ means include latest available version.



回答4:

Please Remove the "+" from gradle file (Module Level) and add the lates version of that both library use short-cut-key ctrl+altr+shift+s "project structure" click on dependencie

dependencies {
com.google.android.gms:play-services-maps:10.0.1
com.google.android.gms:play-services-location:10.0.1
}
apply plugin: 'com.google.gms.google-services'


回答5:

As you can read at https://docs.gradle.org/current/userguide/userguide_single.html#sub:dynamic_versions_and_changing_modules, just a + as version is not allowed.
You can write something like 1.+ meaning latest version that starts with 1..
If you always want the latest available version, use latest.integration as version like documented in above link.