oney / react-native-gcm-android

GCM for React Native Android
MIT License
172 stars 76 forks source link

Execution failed for task ':app:transformClassesWithDexForDebug'. #32

Closed nbastoWM closed 8 years ago

nbastoWM commented 8 years ago
* What went wrong:
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 '/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

I tried to run the example and everything went OK. When I tried to install this module onto my App, that error appears.

I don't have multiDexEnabled and I'm running on an Android device with RN 0.17.

notlose commented 8 years ago

i got the same error

notlose commented 8 years ago

rn 0.18.0

oney commented 8 years ago

Try running ./gradlew app:dependencies in android directory in terminal

notlose commented 8 years ago

i found the way to solve this problem. just remove both 'build' folder in /android and /android/app and build again with 'react-native run-android'

oney commented 8 years ago

Good!

nbastoWM commented 8 years ago

Neither solution worked for me. I even removed the folder node_modules and did npm install again.

The full error:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzlv;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)

:app:transformClassesWithDexForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
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 '/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
oney commented 8 years ago

@nbastoWM Can you share your project android/build.gradle and android/app/build.gradle

nbastoWM commented 8 years ago

android/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.3.1'
        classpath 'com.google.gms:google-services:1.4.0-beta3' // <- Add this line

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

allprojects {
    repositories {
        mavenLocal()
        jcenter()
    }
}

android/app/build.gradle

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'           // <- Add this line

apply from: "react.gradle"

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.wmmycityapp"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled false  // Set this to true to enable Proguard
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
}

dependencies {
    compile project(':react-native-google-analytics-bridge')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:0.17.+"
    compile project(':reactnativemapboxgl')
    compile project(':react-native-image-picker')
    compile project(':react-native-icons')
    compile project(':RNDeviceInfo')
    compile project(':react-native-contacts')
    compile project(':reactdate')

    compile "com.google.android.gms:play-services-gcm:8.1.0" // <- Add this line
    compile project(':RNGcmAndroid')                         // <- Add this line
    compile project(':react-native-system-notification')     // <- Add this line
}
nbastoWM commented 8 years ago

I got it running by changing to:

compile "com.google.android.gms:play-services-gcm:8.3.0"

and

classpath 'com.google.gms:google-services:1.5.0-beta3'

oney commented 8 years ago

Good! This solution will help many people that encounter this issue.

vikassy commented 8 years ago

Yup ! I had faced the same issue, @nbastoWM solution worked pretty well. Can I update the Readme, if there is no compatible problem with play-services-gcm:8.3.0 and google-services:1.5.0-beta3 ?

oney commented 8 years ago

@vikassy Please do it, thanks.

lynndylanhurley commented 8 years ago

@nbastoWM - I made those changes, but I'm still only able to build the app with multiDexEnabled = true. I tried deleting both of my build folders and updating those two packages, but nothing seems to work except multiDexEnabled = true. Is there anything else that you may have done to get past this issue that you're leaving out?

pewh commented 8 years ago

@lynndylanhurley I'm not sure but you may try to delete android/app/src/main/assets/index.android.bundle. Let me know if it doesn't work.

dcflow commented 8 years ago

I'm having the same issue. @lynndylanhurley Did you find any solutions? @oney I tried to run the project without compile "com.google.android.gms:play-services-gcm:8.3.0" and classpath 'com.google.gms:google-services:1.5.0-beta3' but I still get the same error. Do you think this has to do with the GCM libraries or with your code?

lynndylanhurley commented 8 years ago

I just had to set multiDexEnabled = true. I don't really understand the implications, but people seem to discourage it. But it hasn't caused me any problems.

Noitidart commented 7 years ago

i found the way to solve this problem. just remove both 'build' folder in /android and /android/app and build again with 'react-native run-android'

@notlose thanks you! I struggled with this issue for two hours! This fixed it!

1c7 commented 6 years ago

@notlose Solution work for me! ( I am using React Native 0.51 ) after remove both /android/build and /android/app/build and re-run

cd android && ./gradlew assembleRelease

Success!

image

RassaLibre commented 6 years ago

Had the same issue and the solution that worked for me was to add this to my build.gradle:

dexOptions { jumboMode true }

I also added dex.force.jumbo=true to my gradle.properties just to be sure. Seems like that did the magic.

AliShhady commented 6 years ago

Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.

com.android.build.api.transform.TransformException: java.lang.IllegalStateException: Dex archives: setting .DEX extension only for .CLASS files this error in my app please help my

sarmad1995 commented 6 years ago

Try adding this in your android/app/build.gradle

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.getRequested().getGroup() == 'com.google.android.gms') {
            details.useVersion('9.8.0')
        }
    }
}
julio-arcila commented 6 years ago

In my case gradle was not in the environment variables. Check in terminal for the command gradle. If not recognized first you have to find the folder of gradle in configuration> settings> build of the android studio. The bin is added to the environment variables. Check again the gradle word in terminal later it runs ./gradlew in unix like systems from the terminal or .\ gradlew in the powershell of windows

tb56zily commented 6 years ago

If java 8 or above is used then the problem is the libraries we use are incompatible with java 8. So to solve this add these two lines to build.gradle of your app and all sub modules if any. (Android studio clearly show how to do this in error message)

targetCompatibility = '1.7' sourceCompatibility = '1.7'

MaheshNandam commented 6 years ago

Below lines works for me,

compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }

saeedjamshidi commented 5 years ago

there's no need to remove "build" folders manually, just run "gradlew clean" command in android folder.

sturmenta commented 5 years ago

@MaheshNandam In what file did you add those lines?

MaheshNandam commented 5 years ago

@sturmenta , it's in android/app/build.gradle

projetoarduino commented 5 years ago

Work to me react-native init projectwebrtc cd projectwebrtc npm i -s react-native-webrtc react-native link react-native-webrtc

and in android/app/build.gradle add inside android section:

compileOptions { sourceCompatibility = '1.8' targetCompatibility = '1.8' }

normanbanzon commented 5 years ago

remove android folder run

react-native upgrade then

react-native run-android

haizo-code commented 5 years ago

This worked for me after 4 hours of trying, by adding this to the module dependencies :

dependencies {
    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v13'
    }
....
}

I hope this helps 👍

rvilardo commented 5 years ago

If you are running on Terminal, check if the java version you are using is 1.8. $ java -version depending on gradle version you might have issues with java 1.8+ So, install the 1.8 version and change the JAVA_PATH to: export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)" Make sure it's on your PATH as well

Vladus7 commented 5 years ago

Please tell me where I need to enter the command 'react-native run-android' ?

GeronimoKTT commented 5 years ago

i found the way to solve this problem. just remove both 'build' folder in /android and /android/app and build again with 'react-native run-android'

Very good!

froliveira94 commented 4 years ago

If your minSdkVersion is lower then 21 you need to add multiDexEnabled = true on app/build.gradle

reference: https://developer.android.com/studio/build/multidex

prakashsaran commented 4 years ago

If your minSdkVersion is lower then 21 you need to add multiDexEnabled = true on app/build.gradle

reference: https://developer.android.com/studio/build/multidex

help full for me

gvsakhil commented 4 years ago

Deleting build folders didnot solve my issue

I need to delete some hidden folders too. Change settings to view hidden folders ( cmd +shift + . in mac)

Delete build, .gradlew, .idea, files with .iml in android folder Delete build folder in android/app

Now go back and run react-native run-android

Good luck :)

ravi-pandit14 commented 4 years ago

In app/build.gradle add

defaultConfig{
...
multiDexEnabled true            //add this 
}
pushpanathank commented 4 years ago

Refer this

android { defaultConfig { ... minSdkVersion 21 targetSdkVersion 26 multiDexEnabled true <---- Add this } ... }

https://stackoverflow.com/questions/46774530/execution-failed-for-task-apptransformclasseswithdexfordebug-in-react-native/46775061

ManalLiaquat commented 4 years ago

Hey everyone! I am getting this error when generating release apk, in debug works fine

> Task :app:mergeDexRelease FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDexRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > java.lang.OutOfMemoryError (no error message)
Darkensses commented 4 years ago

I'm using react-native-maps and my issue was Execution failed for task ':app:mergeDexDebug'. I solved by editing the app/build.gradle:

android {
    defaultConfig {
        // ...
        multiDexEnabled true
    }
    // ...
}
pke commented 4 years ago

Thanks @Darkensses this worked. I wonder why the tooling does not enable this by default. But I guess it would prevent the app from running on very old Android devices? With this setting it runs on my baseline Android 5 device without problems.

hasnainalimj commented 4 years ago

I got the same error after using react-native-firebase SDK but after adding multiDexEnabled true inside android/app/build.gradle it's work for me Thanks @lynndylanhurley

pranshuchittora commented 3 years ago

Just delete android/.gradle and 'android/app/build'.

Reasons for the issue.

wdevon99 commented 3 years ago

I just had to set multiDexEnabled = true. I don't really understand the implications, but people seem to discourage it. But it hasn't caused me any problems.

Thanks alot this worked! <3