Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execution failed for task ':app:transformClassesWithDexForDebug' in react native

I am new in react native and I use it in Ubuntu. I would like to run a project on my PC. I use yarn and android emulator. Here is my installed application versions:

yarn: 1.2.0

nmp: 3.10.10

I got the following error while use:

$ react-native run-android

Here is the error:

  * What went wrong:
    Execution failed for task ':app:transformClassesWithDexForDebug'.
    > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

I have tested many solutions that exist in stackoverflow but, non of them did't work for me. such as:

Adding google services - Execution failed for task ':app:processDebugResources'

Error:Execution failed for task ':app:transformClassesWithDexForDebug' in android studio

I also use Google play service and I have installed Firebase plugin. Do you have idea that what should I do?

like image 395
Queen Avatar asked Oct 16 '17 16:10

Queen


2 Answers

This worked for me, when you're inside your project directory try using:

cd android && gradlew clean
cd .. && react-native run-android

Source: https://github.com/facebook/react-native/issues/10367#issuecomment-308153481

like image 51
zashishz Avatar answered Nov 20 '22 01:11

zashishz


My guess is you are over the 64k reference limit and need to enable multidexing. The second article you linked referenced how to solve this, but many react-native projects are initialized with minSdkVersion of 16, so there is an extra step to enabled multidex. You have two options.

Option 1:

Upgrade your minSdkVersion to 21 in your AndroidManifest.xml file (android/app/src/main/AndroidManifest.xml) and also your build.gradle file (android/app/build.gradle), then in your build.gradle file add multiDexEnabled to true in this line

android {
    defaultConfig {
        ...
        minSdkVersion 21 
        targetSdkVersion 26
        multiDexEnabled true
    }
    ...
} 

Option 2:

If you need to stay at minSdkVersion 16, set multiDexEnabled to true in your build.gradle file, then add this line under "dependencies" in the same file

dependencies {
  compile 'com.android.support:multidex:1.0.1'
  ...(your other dependencies here)
}

Then depending on whether you override the Application class, perform one of the following:

If you do not override the Application class, edit your manifest file to set android:name in the tag as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myapp">
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
</manifest>

If you do override the Application class in android/app/src/main/java/MainApplication.java, change it to extend MultiDexApplication (if possible) as follows:

public class MyApplication extends MultiDexApplication { ... }

Here is android's documentation on what this error means and why it occurs, as well as how to fix it https://developer.android.com/studio/build/multidex.html

like image 34
wizloc Avatar answered Nov 20 '22 03:11

wizloc