2017-10-13 398 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