問題描述
我正在嘗試在 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.
這篇關于無法解決:帶有 gradle 的 IntelliJ Idea 中的 com.google.android.gms:play-services的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!