10

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?

6
  • Can you share your AndroidManifest.xml file? Commented Oct 16, 2017 at 16:11
  • @wizloc: Thanks for your reply. Where can I find it in my project? Is it in current path of the project? I could't find it! I should mention that the project was completely worked in the other PC! Commented Oct 16, 2017 at 16:16
  • android/app/src/main/AndroidManifest.xml. Specifically I'm just curious what the android:minSdkVersion field value is. My guess is 16? Commented Oct 16, 2017 at 16:19
  • @wizloc: Yes you are right! it is 16! <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22"/> Commented Oct 16, 2017 at 16:21
  • @wizloc: Could you guess the problem? :) Commented Oct 16, 2017 at 16:23

4 Answers 4

15

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer but, it gave me the same error. :(
If you can copy and paste your android/app/build.gradle file, I can take another look
with mixing your answer and one of the anwser above, finally I could fix it. Thanks a lot. :)
Mine minSdkVersion was at 19 and a I had to upgrade it to 21 as well and that fix my problem, thanks!
7

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

Comments

0

if you are getting this error by generating the Release app then you can follow this answer :-https://stackoverflow.com/a/57548822/9444013

Comments

0

after 2 hours of searching this Solution works for me! cmd cd android then ./gradlew assembleDebug --stacktrace

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.