【问题标题】:Installing Google Play Services [duplicate]安装 Google Play 服务 [重复]
【发布时间】:2018-03-25 17:43:11
【问题描述】:

我想将位置 API 与 Google Play 服务一起使用

这是顶级 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
}

这是我的应用级 gradle 文件:

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

我已通过单击“安装存储库和同步项目”安装了 Google Play 服务,但仍然显示错误

根据本文档: https://developers.google.com/android/guides/setup 我已经用这行替换了 google-play-services 依赖项:

compile 'com.google.android.gms:play-services-location:11.4.2'
compile 'com.google.android.gms:play-services-maps:11.4.2'

当我构建项目时,显示“无法解决...”错误,但是当我点击“安装存储库并同步项目”时什么也没发生!

有什么问题?版本号有问题?还是别的什么?!

【问题讨论】:

  • 您是否在项目级 Gradle 中添加了 Maven 存储库?
  • @NovoLucas ,我在帖子中添加了顶级gradle文件
  • 类路径 'com.google.gms:google-services:3.0.0'
  • 你试过以前的版本吗?

标签: android google-play-services google-location-services


【解决方案1】:

根据 HERE 所写的内容,要使用 11.2.0 版的 google play 服务,您的项目 compileSdkVersion 必须至少设置为 26 版。

当您将应用的 Play 服务依赖项升级到 11.2.0 或更高版本时,还必须更新应用的 build.gradle 以指定 compileSdkVersion 至少为 26 (Android O)。这不会改变您的应用程序的运行方式。您不需要更新 targetSdkVersion。

由于您的项目在 25 版上运行,因此您可以在 gradle 中导入的最大 google play 服务版本为 11.0 版。

compile 'com.google.android.gms:play-services-location:11.0'

【讨论】:

  • 错误:(20, 0) 找不到方法 google() 用于存储库容器上的参数 []。
  • 查看我编辑的帖子。你是在 26 以下运行 compileSDK 吗?
  • 我刚刚向您展示了问题的根源并为您提供了解决方案
【解决方案2】:

您需要将以下内容添加到您的项目级 Gradle 文件中:

allprojects { 
repositories {
 maven { url "https:// maven.google.com" }
  }
 }
//This is when you are using a version of Gradle below 4.1.

注意 - 如果你遵循这个,那么你还需要降级你的播放服务依赖版本。更好的方法是更新到最新的 compileSDKVersion

【讨论】:

  • google() 已经有一段时间了。如果您使用的是最新工具,则无需明确设置 URL
  • 但这在 2.3.3 中不起作用
  • 这就是为什么会有更新
  • 我完全同意你的看法,但我的回答是基于 OP 提到的错误
  • 如果您阅读了我的回答,您就会明白他做错了什么并且与存储库无关
猜你喜欢
  • 2014-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-25
  • 2014-08-30
  • 2013-09-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多