Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nbastoWM opened this issue Jan 22, 2016 · 44 comments
Closed

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

nbastoWM opened this issue Jan 22, 2016 · 44 comments

Comments

@nbastoWM
Copy link

* 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
Copy link

notlose commented Jan 22, 2016

i got the same error

@notlose
Copy link

notlose commented Jan 22, 2016

rn 0.18.0

@oney
Copy link
Owner

oney commented Jan 22, 2016

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

@notlose
Copy link

notlose commented Jan 22, 2016

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
Copy link
Owner

oney commented Jan 22, 2016

Good!

@nbastoWM
Copy link
Author

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
Copy link
Owner

oney commented Jan 22, 2016

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

@nbastoWM
Copy link
Author

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
Copy link
Author

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
Copy link
Owner

oney commented Jan 25, 2016

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

@oney oney closed this as completed Jan 25, 2016
@vikassy
Copy link
Contributor

vikassy commented Jan 29, 2016

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
Copy link
Owner

oney commented Jan 29, 2016

@vikassy Please do it, thanks.

@lynndylanhurley
Copy link

@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
Copy link

pewh commented Feb 1, 2016

@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
Copy link

dcflow commented Feb 26, 2016

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
Copy link

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
Copy link

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
Copy link

1c7 commented Jan 12, 2018

@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
Copy link

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
Copy link

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
Copy link

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
Copy link

julio-arcila commented May 17, 2018

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
Copy link

tb56zily commented Jun 15, 2018

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
Copy link

Below lines works for me,

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

@saeedjamshidi
Copy link

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

@sturmenta
Copy link

@MaheshNandam In what file did you add those lines?

@MaheshNandam
Copy link

MaheshNandam commented Sep 29, 2018

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

@projetoarduino
Copy link

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
Copy link

remove android folder run

react-native upgrade
then

react-native run-android

@haizo-code
Copy link

haizo-code commented May 6, 2019

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
Copy link

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
Copy link

Vladus7 commented Jul 7, 2019

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

@GeronimoKTT
Copy link

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
Copy link

froliveira94 commented Aug 19, 2019

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
Copy link

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
Copy link

gvsakhil commented Jan 9, 2020

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
Copy link

In app/build.gradle
add

defaultConfig{
...
multiDexEnabled true            //add this 
}

@pushpanathank
Copy link

pushpanathank commented Feb 28, 2020

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
Copy link

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
Copy link

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
Copy link

pke commented May 18, 2020

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
Copy link

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
Copy link

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

Reasons for the issue.

  • Renaming the app folder.
  • Moving the project directory.
  • File System rewired

@wdevon99
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests