I\'m trying to add google play services to my libGDX project in IntelliJ Idea. I\'ve followed the setup guide here: https://developers.google.com/android/guides/setup
<A more up to date answer:
allprojects {
repositories {
google() // add this
}
}
And don't forget to update gradle to 4.1+ (in gradle-wrapper.properties):
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
source: https://developer.android.com/studio/build/dependencies.html#google-maven
I have found following solution to replace following code
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.google.gms:google-services:3.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
It's work fine for me
this is probably about you don't entered correct dependency version. you can select correct dependency from this:
file>menu>project structure>app>dependencies>+>Library Dependency>select any thing you need > OK
if cannot find your needs you should update your sdk from below way:
tools>android>sdk manager>sdk update>select any thing you need>ok
Google Play services SDK is inside Google Repository
.
Start Intellij IDEA.
On the Tools menu, click Android > SDK Manager.
Update the Android SDK Manager: click SDK Tools, expand Support Repository, select Google Repository, and then click OK.
Current Google Repository version is 57.
After update sync your project.
EDIT
From version 11.2.0
, we've to use the google maven repo so add google maven repo link in repositories tag. Check release note from here.
allprojects {
..
repositories {
...
maven {
url 'https://maven.google.com'
// Alternative URL is 'https://dl.google.com/dl/android/maven2/'
}
}
}
I had that problem. And I found this solve. In Android Studio, Open File menu, and go to Project Structure, In Module app, go to dependencies tab and you can add 'com.google.android.gms:play-services:x.x.x' by clicking on + button.
I just replaced version 11.2.0 with 11.0.0 and then it seemed to work fine, so that had to mean that 11.2.0 wasn't included with the latest Android SDK.
So, after struggling with all the available scattered documentation, I reached this document by pure chance (I guess it is not indexed high enough by Google): https://developers.google.com/android/guides/releases
I quote from there:
Highlights from the Google Play services 11.2 release. Google Play services dependencies are now available via maven.google.com
Now, even when that shouldn't necessarily mean that they are not available with the downloaded SDK anymore, it seems that this is actually the case.
Anyway, adding google() to my build.gradle didn't work (not found, undefined, or whatever...), so I used a different approach that I found in this document referenced from the previous one:
https://developer.android.com/studio/build/dependencies.html#google-maven
I modified my build.gradle file adding that line to allprojects/repositories, as in:
allprojects {
...
repositories {
...
maven { url "https://maven.google.com/"}
}
}
And then also in the android section in the same build.gradle file:
project(":android") {
...
dependencies {
...
compile 'com.google.android.gms:play-services-ads:11.2.0'
}
}
Those two lines were enough to make Gradle sync without problems. I didn't need to add any plugins apart from the ones that are already added in my libGDX project by default.
After that, I got a few different errors, but none about Gradle or dependencies. In a brief, JFTR:
First, I had a minSdkVersion of 8. Solved by raising it to 14. I think I could live without supporting all those devices below 14.
Second, I had problems with the dex upper limit of references. I've never faced this problem before, but maybe you've already noticed the solution I used: instead of compiling the whole 'com.google.android.gms:play-services' I used only 'com.google.android.gms:play-services-ads' that's the API I'm actually interested right now. For those other particular cases where a solution like this may not be useful, this document could provide some better insight: https://developer.android.com/studio/build/multidex.html
Third, even after that I got this "jumbo" thing problem described and answered here: https://stackoverflow.com/a/26248495/1160360
And that's it. As of now, everything builds and my game does finally shows those Admob banners.
I've spent hours with this, thought, which makes me wonder if all these building automation systems we are using lately are worth the extra load they add.
I mean, the first time I had to add Admob to an app five years ago or so, I just had to download a .jar file and put it on a directory on my project. It was pretty obvious and the whole process, from googling "how to setup Admob in my android project" to have my app showing an Admob banner took me just a few minutes. I'm gonna leave it here, since this is not the place for such kind of debate.
Nonetheless, I hope my own experience is useful for someone else further.