Reputation: 1548
I am trying to implement google cloud messaging and push notifications on my android app
I am following official google tutorial , I am using android studio
https://developers.google.com/cloud-messaging/android/client
and I am getting this error
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
here is my 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:0.4@aar'
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'
}
also here is my project build.gradle file
// 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()
}
}
Upvotes: 2
Views: 2447
Reputation: 6160
After some-days and nightmares, Finally I can defeat the problem and believe it could be of help to others.
Because of my massive coded project, test and checking each advice takes about 5 minutes of my system to build. I examined almost all of SO community suggestions and I wanna conclude them here:
This is most likely a problem with the dependencies you have listed in your build.gradle
file for you app.
Things I do not recommend:
Unless you have an absolute need to enable multiDex in your build.gradle DO NOT DO IT, this is just stepping over the underlying problem in your app and not getting to the root of it. You are also unnecessarily increasing the size of your apk, and there could be unexpected crashes when there is a conflicting method in your dex file.
Things to look out for:
Check all your dependencies in your build.gradle file if you have any duplication. Are you referencing a dependency that also includes a dependency you have already included? For example, if your including appcompat-v7 there is no need to include appcompat-v4 since v7 includes all features from v4.
My Issue: GOOGLE PLAY SERVICES >> causing my app to exceed method limit in my dex file.
If you do not need all the google play services library dependencies DO NOT INCLUDE this line in your build.gradle compile 'com.google.android.gms:play-services:8.3.0'
and instead just use what you need!! also check if your can build correctly with lower versions of the dependency.
Google has a comprehensive list of the libraries for selectively compiling here
With all that said you probably only need to include this one line in gradle for your Google Analytics:
dependencies{
compile 'com.google.android.gms:play-services-plus:8.3.0'
}
Well Done!
Upvotes: 4
Reputation: 1145
take a look in your gradle console and check the exact error
i just had the same problem. i solved it with:
Upvotes: 3
Reputation: 5829
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
}
Upvotes: 2