2015-09-27 103 views
4

我想實現谷歌雲通訊和我的Android應用的推送通知雲通訊和Android

我關注的谷歌官方的教程中,我使用過Android Studio

https://developers.google.com/cloud-messaging/android/client

和我收到此錯誤

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. 
> com.android.build.transform.api.TransformException:  com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2 

,這裏是我的build.gradle

apply plugin: 'com.android.application' 
apply plugin: 'com.google.gms.google-services' 


android { 
    packagingOptions { 
    exclude 'META-INF/DEPENDENCIES' 
    exclude 'META-INF/NOTICE' 
    exclude 'META-INF/LICENSE' 
    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/NOTICE.txt' 
    exclude 'META-INF/ASL2.0' 
    exclude 'META-INF/notice.txt' 
} 
compileSdkVersion 22 
buildToolsVersion "23.0.0 rc2" 

defaultConfig { 
    applicationId "com.myapp.example" 
    minSdkVersion 15 
    targetSdkVersion 22 
    versionCode 1 
    versionName "1.0" 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
    } 
} 
sourceSets.main { 
    jniLibs.srcDir 'libs' 
    jni.srcDirs = [] //disable automatic ndk-build call 
} 

} 


dependencies { 
compile fileTree(dir: 'libs', include: ['*.jar']) 
compile 'com.google.android.gms:play-services:8.1.0' 
compile 'com.android.support:appcompat-v7:22.2.0' 
compile 'org.java-websocket:Java-WebSocket:1.3.0' 
compile 'com.github.nkzawa:socket.io-client:0.3.0' 
compile 'rongi.rotate-layout:rotate-layout:1.0.1' 
compile 'com.vdurmont:emoji-java:2.0.1' 
compile 'commons-lang:commons-lang:2.5' 
compile 'com.github.javadev:underscore:1.6' 
compile 'com.astuetz:pagerslidingtabstrip:1.0.1' 
compile 'org.florescu.android.rangeseekbar:rangeseekbar-library:0.2.0' 
compile 'com.beardedhen:androidbootstrap:1.1.1' 
compile 'com.mcxiaoke.volley:library:1.0.18' 
compile 'com.reginald.swiperefresh:library:1.1.1' 
compile 'com.makeramen:roundedimageview:2.2.0' 
compile 'com.google.code.gson:gson:2.3.1' 
compile 'com.github.d-max:spots-dialog:[email protected]' 
compile 'cn.pedant.sweetalert:library:1.3' 
compile 'com.jakewharton:butterknife:6.1.0' 
compile 'com.squareup.picasso:picasso:2.5.2' 
compile 'in.srain.cube:grid-view-with-header-footer:1.0.12' 
compile 'com.vstechlab.easyfonts:easyfonts:1.0.0' 

} 

也在這裏是我的項目的build.gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

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

allprojects { 
    repositories { 
    jcenter() 
} 
} 
+0

我有類似的問題。我將項目build.gradle谷歌服務版本更改爲classpath'com.google.gms:google-services:1.3.0'並且它工作了 – subhash

+0

它沒有工作,您可以發佈您的gradle.build文件 –

回答

2
Add one more file in your dependency list 
compile 'com.android.support:multidex:1.0.0' 

and add following to your defaultconfig 
defaultConfig { 
//your stuff 
     multiDexEnabled true 
} 
+0

添加multidexenabled可以解決的問題,但它使建築時間如此之久,也有很多缺點 –

+0

@Remon或者減少使用的庫的數量或使用多重dexing,沒有其他選擇 – Samir

+0

不再是,隨着gradle構建和隨後的構建時間在2 -5秒,如果你正在使用設備調試,應用程序的實際性能也相當不錯。你有另一種選擇是使用proguard。你可以掩蓋你不需要的類。 http://developer.android.com/tools/help/proguard.html –

6

經過一些天的和噩夢,最後我能打敗這個問題,並認爲它可能是幫助他人。

由於我的大量編碼項目,測試和檢查每個建議大約需要5分鐘我的系統構建。我檢查幾乎所有的SO社區的建議,我想在這裏總結他們:

這是最有可能一個問題,你在你的build.gradle文件的應用程序爲您列出的依賴關係。

事情,我不建議:

除非你有絕對的需要在 的build.gradle使multiDex 不這樣做,這僅僅是跨過在 根本問題你的應用程序,而不是它的根源。您的 也不必要地增加了您的apk的大小,並且 在您的 dex文件中存在衝突的方法時可能會出現意外的崩潰。

事情看出來:

檢查所有的依賴在你的build.gradle文件,如果您有任何 重複。您是否引用了一個依賴項,該依賴項還包括您已經包含的 依賴項?例如,如果包含 appcompat-v7,則不需要包含appcompat-v4,因爲v7 包含v4的所有功能。

我的問題:Google Play服務 >>使我的應用程序在我的DEX文件超過方法的限制。

如果你不需要所有的谷歌播放服務庫依賴不要包括在你的build.gradle compile 'com.google.android.gms:play-services:8.3.0'這行,而只是使用你所需要的!還要檢查你的版本是否可以用較低版本的依賴項正確構建。

谷歌擁有的庫,用於選擇性地編制here

說了這麼多,你可能只需要在gradle產出這一行你的谷歌Analytics(分析)的完整列表:

dependencies{ 
     compile 'com.google.android.gms:play-services-plus:8.3.0' 
    } 

做得好!

+1

很好的答案。單個dex文件只能容納65,536個方法,包括每個android框架方法,谷歌播放服務方法等[此說明](http://developer.android.com/intl/ko/tools/building/multidex.html)將會有幫助。 – Aigori