Android 安装Google Play服务
我想在Google Play服务中使用位置API 这是顶级渐变文件:Android 安装Google Play服务,android,google-play-services,google-location-services,Android,Google Play Services,Google Location Services,我想在Google Play服务中使用位置API 这是顶级渐变文件: buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.3' // NOTE: Do not place your application dependencies here; they belong
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "..."
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
// exclude group: 'com.android.support', module: 'support-annotations'
// })
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.google.android.gms:play-services:11.4.2'
}
这是我的应用程序级gradle文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "..."
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
// exclude group: 'com.android.support', module: 'support-annotations'
// })
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.android.support:recyclerview-v7:25.0.1'
compile 'com.google.android.gms:play-services:11.4.2'
}
当我要生成项目时,此错误显示:
Error:(30, 13) Failed to resolve: com.google.android.gms:play-services:11.4.2
Install Repository and sync project
Show in File
Show in Project Structure dialog
我已经通过点击“安装存储库和同步项目”安装了GooglePlay服务,但仍然显示错误
根据本文件:
我已将google play服务依赖项替换为以下内容:
compile 'com.google.android.gms:play-services-location:11.4.2'
compile 'com.google.android.gms:play-services-maps:11.4.2'
当我构建项目时,显示了“未能解决…”错误,但当我单击“安装存储库和同步项目”时,什么都没有发生
有什么问题?版本号有问题吗?还是别的什么 根据所写内容,要使用11.2.0版的google play服务,您的项目compileSdkVersion
必须至少设置为26版
将应用程序的Play services依赖项升级到11.2.0或更高版本时,还必须更新应用程序的build.gradle,以指定至少26(Android)的CompileSDK版本。这不会改变应用程序的运行方式。您无需更新targetSdkVersion
由于您的项目在版本25上运行,您可以在gradle中导入的最大google play服务版本是版本11.0
compile 'com.google.android.gms:play-services-location:11.0'
您需要将以下内容添加到项目级渐变文件中:
allprojects {
repositories {
maven { url "https:// maven.google.com" }
}
}
//This is when you are using a version of Gradle below 4.1.
注意-如果您遵循此操作,则还需要降级您的play services依赖项版本。更好的方法是更新到最新版本的编译器dkversion是否在项目级Gradle中添加了Maven Repo?@NovoLucas,我在后classpath“com.google.gms:google services:3.0.0”中添加了顶级Gradle文件是否尝试了以前的版本?错误:(20,0)找不到参数的方法google()在存储库容器上。检查我编辑的文章。您是否正在运行低于26的compileSDK?我刚刚向您展示了问题的根源,并为您提供了解决方案有
google()
一段时间了。如果您正在使用最新的工具,则无需明确设置URL,但这在2.3.3中不起作用。这就是为什么会有更新。我完全同意您的看法,但我的回答是基于OP提到的错误。如果您阅读我的回答,您将了解他做错了什么,并且与存储库无关