2016-09-18 94 views
4

我想在我的應用程序中添加firebase addmob。如何解決錯誤:無法找到com.google.gms:google-services:3.0.0。?

在的build.gradle(項目)我有下面的代碼

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.google.gms: google-services: 3.0.0' 
     classpath 'com.android.tools.build:gradle:2.1.3' 

     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

在的build.gradle(模塊)

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "24.0.2" 

    defaultConfig { 
     applicationId "com.myname.examp.myapp" 
     minSdkVersion 14 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.0.0' 
    compile 'com.android.support:design:23.0.0' 
    compile 'com.google.firebase: firebase-ads: 9.0.0' 
} 
apply plugin: 'com.google.gms.google-services' 

我已經更新了谷歌Play版本服務和存儲庫 enter image description here

當我同步項目仍然我得到以下錯誤

Error:Could not find com.google.gms: google-services: 3.0.0. 
Searched in the following locations: 
    file:/C:/Program Files/Android/Android Studio2/gradle/m2repository/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.pom 
    file:/C:/Program Files/Android/Android Studio2/gradle/m2repository/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.jar 
    https://jcenter.bintray.com/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.pom 
    https://jcenter.bintray.com/com/google/gms/ google-services/ 3.0.0/ google-services- 3.0.0.jar 
Required by: 
    :MyApplication:unspecified 

有人能幫助我如何解決這個錯誤

+0

您是否在應用程序文件夾中添加了「google-services.json」。 –

+0

@AmanJain.Please在答案中添加這個,所以我可以接受你的答案。謝謝你的答案。我認爲google-services.json不需要安裝庫 – vision

+0

無論誰給予投票下來,請告訴我why.so我可以改善下次我已經解釋了我的問題儘可能好 – vision

回答

5

請在您的應用程序文件夾添加google-services.json

+0

謝謝阿曼耆那教徒 – vision

+2

即使在添加google-service.json文件後,這對我也不起作用。它仍然給出同樣的錯誤。 –

+0

有關設置GA的說明中沒有提及此文件。 我在哪裏得到這個文件? –

5

我有類似的問題,我從firebase指令中複製了依賴項並粘貼了代碼。

從指令:

classpath 'com.google.gms: google-services: 3.0.0' 

應該是:

classpath 'com.google.gms:google-services:3.0.0' 

不應包含任何空格。傻了,但浪費了半個小時。

3

在頂層gradle文件中添加類路徑行。不在您添加個別依賴項的相同文件中。

-2

錯誤:org.gradle.api.internal.tasks.DefaultTaskInputs $ TaskInputUnionFileCollection不能轉換到org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection 可能的原因爲這個意外的錯誤包括:

  • 搖籃的相關性高速緩存可能會損壞(有時會在網絡連接超時後發生)。 重新下載依賴項和同步項目(需要網絡)
  • Gradle構建過程(守護進程)的狀態可能已損壞。停止所有的Gradle守護進程可能會解決這個問題。 停止Gradle構建過程(需要重新啓動)
  • 您的項目可能使用與項目中的其他插件或項目請求的Gradle版本不兼容的第三方插件。
在發生損壞的Gradle進程的情況下,您也可以嘗試關閉IDE,然後終止所有Java進程。

0

移動類路徑依賴於項目級build.gradle文件,如下所示:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.3' 
     classpath 'com.google.gms:google-services:3.0.0' 
     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

,並確保應用插件線的應用程序文件夾中的build.gradle文件相關依次如下

apply plugin: 'com.google.gms.google-services' 
0

在項目級別的build.gradle中添加類路徑,而不是在模塊級別的類路徑。

dependencies { 
    classpath 'com.android.tools.build:gradle:2.3.1' 
    classpath 'com.google.gms:google-services:3.+' 

    // NOTE: Do not place your application dependencies here; they belong 
    // in the individual module build.gradle files 
} 

然後將其應用於模塊級別。

apply plugin: 'com.google.gms.google-services' 
相關問題