2016-08-03 73 views
-1

我在啓動我的應用程序時遇到問題。 我一直在谷歌Play服務,在我的應用程序,在我的gradle這個它說:Android Studio - Google Play服務錯誤

compile 'com.google.android.gms:play-services-ads:8.4.0' 
compile 'com.google.android.gms:play-services:8.4.0' 

但現在,我不知道爲什麼,Android的工作室拋出一個錯誤說:

Error:FAILURE: Build failed with an exception. 

* What went wrong: 
Execution failed for task':app:prepareComGoogleAndroidGmsPlayServices840Library'. 
> Could not expand ZIP 'C:\Users\Roman\...\sdk\extras\google\m2repository\com\google\android\gms\play-services\8.4.0\play-services-8.4.0.aar'. 

* Exception is: 
org.gradle.api.tasks.TaskExecutionException: Execution failed for task':app:prepareComGoogleAndroidGmsPlayServices840Library'. 
... 
Caused by: org.gradle.api.GradleException: Could not expand ZIP 'C:\Users\Roman\...\sdk\extras\google\m2repository\com\google\android\gms\play-services\8.4.0\play-services-8.4.0.aar'. 
... 
Caused by: java.util.zip.ZipException: archive is not a ZIP archive 

似乎是嘗試解壓縮.aar ...我如何解決這個問題?

在此先感謝

+0

你也應該注意到,有一個在其播放服務的廣告和播放服務是沒有意義的,因爲這意味着每一個做一個包括廣告。僅包括您需要的特定播放服務。這減少了apk大小和方法數量。 [docs](https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project) – headsvk

回答

0

轉到您的Android SDK管理器,並確保你已經安裝了「谷歌庫」和「谷歌播放服務」庫。這個錯誤是由於gradle無法找到必要的庫來編譯造成的。

+0

已經完成,所有更新我親自檢查了sdk目錄 –

+0

您是否使用最新的gradle wrapper和構建工具? – headsvk

+0

我這麼認爲,我昨天更新了Android Studio –

0

原因是,無論何時我們在android中使用google play服務庫,在編譯build.gradle庫之後,我們必須在應用程序標籤下的android.manifest文件中指定庫版本。

我們通過<meta-data>標籤來做到這一點。需要注意的是直接輸入的版本是不是一個好的做法,所以我們把它用下面的方式

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <meta-data android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" /> 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 
+0

有同樣的問題,它說,它不能解決@ integer/google_play_services_version –

+0

嘗試使用你的庫以這種方式編譯'com.google.android.gms:play-services:8。 +' –

+0

此後嘗試清理或重建您的項目。如果谷歌播放服務通過sdk管理器正確安裝,則可以找到@ integer/google_play_services_version –

相關問題