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
which looks pretty straightforward. I just added those lines to my build.gradle in the corresponding section, so things look now like:
project(":android") {
apply plugin: "android"
apply plugin: 'com.android.application'
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
compile 'com.google.android.gms:play-services:11.2.0'
}
}
Then I try to sync my gradle project in Idea just to get that "Failed to resolve" error.
Well, the setup guide also says "Be sure you update this version number each time Google Play services is updated", but the problem is that it seems nearly impossible to find that version number: my Google Play Services SDK version according to the Android SDK manager is "43", and so far I have been unable to correlate such "11.2.0" or whatever typical version string with the "43" version number. Not that the setup guide says nothing about that.
Anyway, I have tried a lot of things from the plethora of questions related to this to no avail. Specifically, I have to point out that I do have my Android SDK properly updated and I'm sure it is the one it's being used by Idea (I've already triple-checked this...):
I'm using the API level 26, but anyway the other defines do use the very same directory for the Android SDK. Moreover, I do NOT have any other android SDK installed at all in this laptop, so there's no question about Idea being using that one and that one only.
Any ideas are more than welcome.
Thanks in advance!
I had the issue when I put jcenter()
before google()
in project level build.gradle. When I changed the order and put google()
before jcenter()
in build.gradle the problem disappeared
Here is my final build.gradle
// 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'
// 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
}
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.
Add this to your project-level build.gradle
file:
repositories {
maven {
url "https://maven.google.com"
}
}
It worked for me
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With