我想获得我的设备的当前位置,我关注此链接:Google本教程需要Google Play Services版本11.2.0或更高版本。但是当我编译" com.google.android.gms:play-services:11.2.0
"时,我会得到:
Error:(26, 13) Failed to resolve: com.android.support:appcompat-v7:26.0.0
这是我的build.gradle(模块:app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.administrator.googlemap"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
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:26.+'
compile 'com.google.android.gms:play-services:11.2.0'
compile 'com.google.android.gms:play-services-maps:11.0.2'
compile 'com.google.android.gms:play-services-places:11.0.2'
compile 'com.google.android.gms:play-services-location:11.0.2'
testCompile 'junit:junit:4.12'
}
这是我的build.grandle(project)
buildscript {
repositories {
jcenter()
maven { url "https://maven.google.com/"}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.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
}
如何解决此错误?
而不是变量版本名称
compile 'com.android.support:appcompat-v7:26.+'
使用常数版本,最新版本是26.1.0
compile 'com.android.support:appcompat-v7:26.1.0'
您已经在buildscript存储库列表中的Google Maven repo链接,您还应该在项目依赖项中添加Google Maven Repo root build.gradle
文件
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com/"}
}
}
选择性编译是更好的选择,而不是完整的play-services
工件,您应该选择项目中需要的内容。
compile 'com.google.android.gms:play-services:11.2.0' // -> latest is 11.4.0
将其分解成您所需的工件,例如
compile 'com.google.android.gms:play-services-maps:11.4.0'
compile 'com.google.android.gms:play-services-places:11.4.0'
compile 'com.google.android.gms:play-services-location:11.4.0'
如果您使用的是Android插件用于Gradle 3.0.0或后者版本
repositories {
mavenLocal()
mavenCentral()
google() //---> Add this
}
用implementation
替换compile
,有关此更换的更多信息
add
maven {
url 'https://maven.google.com'
}
在您的build.gradle中,即
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
,如果您使用Play Service 11.2.0
,也可以删除其他Google依赖项compile 'com.google.android.gms:play-services:11.2.0'
compile 'com.google.android.gms:play-services-maps:11.0.2'
compile 'com.google.android.gms:play-services-places:11.0.2'
compile 'com.google.android.gms:play-services-location:11.0.2'
to
compile 'com.google.android.gms:play-services:11.2.0'