Java 无法解析:com.google.android.gms:IntelliJ Idea中的play服务与gradle
我正在尝试将google play服务添加到IntelliJ Idea中的libGDX项目中。我在这里遵循了安装指南: 这看起来很简单。我刚刚在相应的部分将这些行添加到我的build.gradle中,因此现在的情况如下所示:Java 无法解析:com.google.android.gms:IntelliJ Idea中的play服务与gradle,java,android,intellij-idea,gradle,libgdx,Java,Android,Intellij Idea,Gradle,Libgdx,我正在尝试将google play服务添加到IntelliJ Idea中的libGDX项目中。我在这里遵循了安装指南: 这看起来很简单。我刚刚在相应的部分将这些行添加到我的build.gradle中,因此现在的情况如下所示: project(":android") { apply plugin: "android" apply plugin: 'com.android.application' configurations { natives } depend
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'
}
}
然后我尝试在Idea中同步我的gradle项目,只是为了得到那个“无法解决”的错误
好的,安装指南还说“确保每次Google Play services更新时都更新此版本号”,但问题是似乎几乎不可能找到该版本号:根据Android SDK管理器,我的Google Play services SDK版本为“43”,到目前为止,我无法关联此类“11.2.0”或者任何带有“43”版本号的典型版本字符串。并不是说《安装指南》没有提到这一点
不管怎样,我已经尝试了很多与此相关的问题,但都没有结果。具体地说,我必须指出,我的Android SDK确实得到了适当的更新,我确信Idea正在使用它(我已经三次检查了这个…):
我使用的是API级别26,但无论如何,其他定义确实使用了与Android SDK完全相同的目录。此外,我根本没有在这台笔记本电脑上安装任何其他android SDK,所以毫无疑问,我只想使用这一个
任何想法都是非常受欢迎的
提前谢谢 Google Play services SDK位于
Google存储库
内
11.2.0
,我们必须使用google maven repo,以便在repositories标签中添加google maven repo链接。检查来自的发布说明
我刚刚用11.0.0替换了11.2.0版,然后它似乎工作得很好,所以这意味着11.2.0没有包含在最新的Android SDK中 因此,在与所有可用的分散文档进行斗争之后,我完全是偶然地找到了这份文档(我猜谷歌对它的索引不够高): 我在此引述: Google Play services 11.2版本的亮点。谷歌游戏 服务依赖项现在可以通过maven.google.com获得 现在,即使这不一定意味着下载的SDK不再提供它们,但事实似乎是这样 无论如何,将google()添加到我的build.gradle中不起作用(未找到、未定义或其他…),因此我使用了与上一个文档不同的方法: 我修改了build.gradle文件,将该行添加到所有项目/存储库中,如下所示:
allprojects {
...
repositories {
...
maven { url "https://maven.google.com/"}
}
}
然后在同一build.gradle文件的android部分:
project(":android") {
...
dependencies {
...
compile 'com.google.android.gms:play-services-ads:11.2.0'
}
}
这两条线足以让Gradle毫无问题地同步。除了默认情况下已经添加到libGDX项目中的插件之外,我不需要添加任何插件
在那之后,我得到了一些不同的错误,但没有关于Gradle或依赖项的错误。简言之,JFTR:
首先,我有一个8的版本。把它提高到14就解决了。我想我可以不支持14岁以下的所有设备
其次,我对引用的dex上限有问题。我以前从未遇到过这个问题,但也许你已经注意到了我使用的解决方案:我没有编译整个“com.google.android.gms:play services”,而是只使用了“com.google.android.gms:play services ads”,这是我现在真正感兴趣的API。对于此类解决方案可能没有用处的其他特定情况,本文档可以提供一些更好的见解:
第三,即使在那之后,我在这里描述并回答了这个“巨型”问题:
就这样。到目前为止,一切都建立起来了,我的游戏最终显示了那些Admob横幅
我花了几个小时思考这个问题,这让我想知道我们最近使用的所有楼宇自动化系统是否值得它们增加额外的负载
我的意思是,大约五年前我第一次不得不将Admob添加到应用程序中时,我只需要下载一个.jar文件并将其放在我项目的目录中。很明显,从谷歌搜索“如何在我的android项目中设置Admob”到让我的应用程序显示Admob横幅,整个过程只花了我几分钟。我将把它留在这里,因为这里不是进行这种辩论的地方
尽管如此,我希望我自己的经验能对其他人有所帮助。我有这个问题。
我找到了解决办法。
在Android Studio中,打开“文件”菜单,进入“项目结构”,在模块应用程序中,进入“依赖项”选项卡,您可以通过单击+按钮添加“com.google.Android.gms:play services:x.x.x” 将其添加到项目级
build.gradle
文件:
repositories {
maven {
url "https://maven.google.com"
}
}
这对我很有效一个更为最新的答案:
allprojects {
repositories {
google() // add this
}
}
不要忘记将gradle更新为4.1+(在gradle wrapper.properties中):
来源:这可能是因为您没有输入正确的依赖项版本。 您可以从以下选项中选择正确的依赖项:
file>menu>project structure>app>dependencies>+>Library Dependency>select any thing you need > OK
如果找不到您的需要,您应该通过以下方式更新sdk:
工具>android>sdk管理器>sdk更新>选择你需要的任何东西>确定最新的
谷歌Play Services 15.0.0
,当你像这样包含整个Play服务时会出现此错误
implementation 'com.google.android.gms:play‐services:15.0.0'
相反,您必须指定详细信息服务,如googledrive
com.google.android.gms:play-services-drive:15.0.0
检查你的梯度设置,它可能被设置为脱机工作我在
google()之前放置jcenter()
时遇到问题
implementation 'com.google.android.gms:play‐services:15.0.0'
com.google.android.gms:play-services-drive:15.0.0
// 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
}
// 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
}
dependencies {
// ...
implementation "com.google.android.gms:play-services-location:{$playServices}"
// ...
}
playServices=15.0.1
dependencies {
// ...
implementation "com.google.android.gms:play-services-location:${playServices}"
// ...
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
implementation "com.google.android.gms:play-services-location:17.0.1"
implementation "com.google.android.gms:play-services-location:17.0.0"