无法解决:带有 gradle 的 IntelliJ Idea 中的 com.google.android.gms:play-services
我正在尝试在 IntelliJ Idea 中将 Google Play 服务添加到我的 libGDX 项目中.我在这里遵循了设置指南:
我使用的是 API 级别 26,但无论如何其他定义确实使用了与 Android SDK 完全相同的目录.此外,我在这台笔记本电脑上根本没有安装任何其他 android SDK,所以毫无疑问,Idea 只使用那个和那个.
欢迎提出任何想法.
提前致谢!
解决方案我刚刚用 11.0.0 替换了 11.2.0 版本,然后它似乎工作正常,所以这意味着 11.2.0 不包含在最新的 Android SDK.
所以,在与所有可用的零散文档苦苦挣扎之后,我纯粹是偶然发现了这个文档(我猜它没有被 Google 索引到足够高的位置):https://developers.google.com/android/guides/releases
我从那里引用:
<块引用>Google Play 服务 11.2 版的亮点.谷歌播放服务依赖项现在可通过 maven.google.com 获得
现在,即使这并不一定意味着下载的 SDK 不再提供它们,但似乎情况确实如此.
无论如何,将 google() 添加到我的 build.gradle 中不起作用(未找到、未定义或其他任何...),因此我使用了在本文档中找到的另一种方法,该方法参考了上一篇:
https://developer.android.com/studio/build/dependencies.html#google-maven
我修改了我的 build.gradle 文件,将该行添加到 allprojects/repositories,如下所示:
所有项目{...存储库{...行家{网址https://maven.google.com/"}}}
然后也在同一个 build.gradle 文件中的 android 部分:
project(":android") {...依赖{...编译'com.google.android.gms:play-services-ads:11.2.0'}}
这两行足以让 Gradle 同步没有问题.除了已经默认添加到我的 libGDX 项目中的插件之外,我不需要添加任何插件.
在那之后,我得到了一些不同的错误,但没有关于 Gradle 或依赖项的错误.简而言之,JFTR:
首先,我的 minSdkVersion 为 8.通过将其提高到 14 来解决.我想我可以不支持所有低于 14 的设备.
其次,我遇到了 dex 引用上限的问题.我以前从未遇到过这个问题,但也许你已经注意到我使用的解决方案:我没有编译整个 'com.google.android.gms:play-services' 我只使用了 'com.google.android.gms:play-services-ads' 这是我现在真正感兴趣的 API.对于像这样的解决方案可能没有用的其他特殊情况,本文档可以提供一些更好的见解:https://developer.android.com/studio/build/multidex.html
第三,即使在那之后,我在此处描述并回答了这个巨型"问题:https://stackoverflow.com/a/26248495/1160360
就是这样.到目前为止,一切都建立起来了,我的游戏终于显示了那些 Admob 横幅.
我在这方面花了好几个小时,我想,这让我想知道我们最近使用的所有这些楼宇自动化系统是否值得它们增加的额外负载.
我的意思是,大约五年前我第一次将 Admob 添加到应用程序时,我只需要下载一个 .jar 文件并将其放在我项目的目录中.很明显,从谷歌搜索如何在我的 android 项目中设置 Admob"到让我的应用显示 Admob 横幅的整个过程只花了我几分钟.我将把它留在这里,因为这里不是这种辩论的地方.
不过,我希望我自己的经验对其他人有用.
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 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.
相关文章