【问题标题】:How to compile play-services:11.2.0 [duplicate]如何编译播放服务:11.2.0 [重复]
【发布时间】:2017-09-27 04:24:20
【问题描述】:

我想获取我设备的当前位置,我点击这个链接:google 而且本教程需要 Google Play 服务版本 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(Module: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
}

如何解决此错误。?

【问题讨论】:

    标签: android google-maps android-gradle-plugin google-play-services android-support-library


    【解决方案1】:

    而不是可变版本名称

    compile 'com.android.support:appcompat-v7:26.+'
    

    使用常量版本,最新的是26.1.0

    compile 'com.android.support:appcompat-v7:26.1.0'
    

    您已经在 buildscript 存储库列表中添加了 google maven 存储库链接,您还应该在您的根 build.gradle 文件的项目依赖存储库列表中添加 google maven 存储库

    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 Plugin for Gradle 3.0.0 或更高版本

    repositories {
          mavenLocal()
          mavenCentral()
          google()        //---> Add this
    } 
    

    implementation替换compile,更多关于这个替换here

    【讨论】:

      【解决方案2】:

      添加

      maven {
              url 'https://maven.google.com'
          }
      

      在你的 build.gradle 中,即

      allprojects {
          repositories {
              jcenter()
              maven {
                  url 'https://maven.google.com'
              }
          }
      }
      

      如果您使用播放服务 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'
      

      compile 'com.google.android.gms:play-services:11.2.0'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-12
        • 1970-01-01
        • 2020-04-03
        • 1970-01-01
        • 2014-01-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多