2015-09-27 52 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