2017-10-13 217 views
2

我想使用位置API与谷歌播放服务安装谷歌播放服务

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

我已经安装了谷歌Play服务,通过点击“安装库和同步工程”,但错误依然显示

根据此文件: https://developers.google.com/android/guides/setup 我已经取代了谷歌播放服务的依赖本线:

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

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

什么问题?版本号有问题?或者是其他东西 ?!

+1

您是否在项目级Gradle中添加了Maven Repo? –

+0

https://stackoverflow.com/questions/46417939/failed-to-resolve-com-google-android-gms-play-services-auth11-4-0 – tyczj

+0

@NovoLucas,我​​在帖子中添加了顶级gradle文件 –

回答

3

从写的是什么HERE,使用谷歌从版本11.2.0项目compileSdkVersion必须设置为,至少,版本26

When you upgrade your app’s Play services dependencies to 11.2.0 or later, your app’s build.gradle must also be updated to specify a compileSdkVersion of at least 26 (Android O). This does not change the way your app runs. You will not be required to update targetSdkVersion.

因为你的项目是在25版本中运行播放服务,您可以在Gradle中导入的最大谷歌播放服务版本是11.0版。

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

错误:(20,0)无法找到存储库容器上参数[]的方法google()。 –

+0

检查我编辑的帖子。你运行compileSDK低于26吗? – Ricardo

+0

我刚刚向你展示了你的问题的来源,并给你提供了解决方案 – Ricardo

0

您需要添加以下到您的项目级别摇篮文件:

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

注意 - 如果你是以下这一点,那么你还需要降级播放业务的依赖版本。更好的方法是更新到最新的compileSDKVersion

+3

有'谷歌()'一段时间了。如果您使用的是最新工具,则不需要明确设置URL –

+0

但是这不适用于2.3.3 –

+0

这就是为什么有更新 – Ricardo