29

I've tried gradlew clean and every other solution available here and on GitHub but the error doesn't match and solution doesn't work

Error on cmd After running react-native run-android

 > Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
    D8: Program type already present: com.google.android.gms.common.api.internal.zzda


    FAILURE: Build failed with an exception.


* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\0.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\1.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\2.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\3.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\4.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\5.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\6.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\7.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\8.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\9.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\10.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\11.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\12.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\13.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\14.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\15.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\16.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\17.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\18.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\19.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\20.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\21.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\22.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\23.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\24.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\25.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\26.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\27.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\28.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\29.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\30.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\31.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\32.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\33.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\34.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\35.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\36.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\37.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\38.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\39.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\40.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\41.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\42.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\43.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\44.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\45.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\46.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\47.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\48.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\49.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\50.jar, C:\New folder\App\android\app\build\intermediates\transforms\dexBuilder\debug\51.jar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 39s
82 actionable tasks: 78 executed, 4 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

I have tried all the solutions but none seems to work. Please Help

react-native-cli: 2.0.1
react-native: 0.53.0


build.gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'

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

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.google.com'
        }
    }
}

ext {
  compileSdkVersion = 26
  targetSdkVersion = 26
  buildToolsVersion = "26.0.2"
  supportLibVersion = "26.1.0"
  googlePlayServicesVersion = "11.8.0"
  oreoEXPERIMENTAL = "yes"
}


android/app/build.gradle file:

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js"
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion 23
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.cherishx_vendors"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    compile project(':react-native-onesignal')
    compile project(':react-native-mauron85-background-geolocation')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

Edit

After adding multidexEnabled = true to android/app/build.gradle file the following error pops up :

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 16s
68 actionable tasks: 1 executed, 67 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

This error is not answered anywhere so I included this as an update to this question.

Sanchit Bhatnagar
  • 874
  • 2
  • 10
  • 16

19 Answers19

39

Got same error a couple of days back, seems you've got to enable multidex to true and delete the build folder.

Go to android/app/build.gradle and add the line multiDexEnabled true and set minSdkVersion to 21 inside defaultConfig like this

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

You can check this thread out on react-native

https://github.com/oney/react-native-gcm-android/issues/32

cmcodes
  • 1,559
  • 19
  • 24
Balanced02
  • 794
  • 7
  • 14
30

I have fixed by enabling the multiDex in the /android/app/build.gradle file.

android {
  defaultConfig {
    .......
    multiDexEnabled true
  }
  ......
}
Zeeshan Ansari
  • 9,657
  • 3
  • 26
  • 27
15

Open the /android/app/build.gradle file.

Under dependencies we need to add the module, and then enable it within defaultConfig

android {
    defaultConfig {
        // ...
        multiDexEnabled true
    }
    // ...
}

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}
Suresh Maidaragi
  • 2,173
  • 18
  • 25
user1948083
  • 151
  • 1
  • 3
6

I solve issue by enabling

android {
    defaultConfig {
        // ...
        multiDexEnabled true
    }
    // ...
}

path : android/app/build.gradle

Salem_Raouf
  • 400
  • 5
  • 10
5

Add following to your android/app/build.gradle

dependencies {
   ....
   implementation 'com.android.support:design:27.1.0'
   ....
}
Aayush Thapa
  • 161
  • 2
  • 6
5

I confronted with this error

Execution failed for task ':app:multiDexListDebug'.

but He wrote in the continuation of my error that

I installed async-storage from two address and when I remove the second

errors have been fixed

"@react-native-async-storage/async-storage": "^1.13.2",

"@react-native-community/async-storage": "^1.12.0", 
atline
  • 28,355
  • 16
  • 77
  • 113
amir behrouzi
  • 155
  • 1
  • 10
  • my case it was the masked-view `@react-native-masked-view/masked-view` and `@react-native-community/masked-view` – U.A Aug 03 '21 at 17:13
4

This will fix it cd android && ./gradlew clean

Subbu
  • 135
  • 7
3

you probably have to add the multiDexEnabled true property to your android/app/build.gradle file.

defaultConfig {
    multiDexEnabled true

    // (...) more properties
}

The console error gives you a hint to overcome this problem. They show you this very link: https://developer.android.com/studio/build/multidex

you can learn more about the problem there. But this was my solution here in 2020. Peace!

2

I have the same issue. So to make it 'clearer', I did these:

  1. Update to sdk27 (compile and target). minSdk is at 21
  2. Update related goodle-play base/services/maps to 15.0.1 (Depends on your project requirement)
  3. Then: I add multidexEnabled=true in the same section as no (1) above
  4. (Optional) - I had another issue where Gradle couldn't find the play-services version properly: I modified the project build.gradle to search the google maven first before the jcenter()

    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
    mavenLocal()
    jcenter()
    
cassmtnr
  • 927
  • 13
  • 26
Yazid
  • 409
  • 7
  • 8
2
At Path android/app/build.gradle

defaultConfig {
multiDexEnabled true //Add this line
}

https://github.com/react-native-community/react-native-webview/issues/1344

sametpalitci
  • 143
  • 1
  • 11
1

As an update to this answer (if people can't figure out why, especially one Mac)

use sudo! I was trying to figure out why gradlew commands were not running for ages, turns out - it didnt have permission!

Use:

sudo ./gradlew [command]

I'm so frustrated and happy at the same time.

JRK
  • 3,686
  • 1
  • 13
  • 19
  • can you check this https://stackoverflow.com/questions/59096566/execution-failed-for-task-apptransformdexarchivewithdexmergerfordebug-rea – Oliver D Nov 29 '19 at 00:32
1

In the file (<your_project_folder>/android/app/build.gradle), amend the code with the following lines:

android {
    ...
   packagingOptions {
       pickFirst '**/libjsc.so'
   }
}

Reference: https://github.com/react-native-community/jsc-android-buildscripts/issues/80

Bilal Abdeen
  • 1,627
  • 1
  • 19
  • 41
1

Just run

cd android && gradlew clean

then

cd .. && react-native run-android
1

Had to use latest dex version

implementation 'androidx.multidex:multidex:2.0.1'
sandaru.ny
  • 105
  • 7
1

I tried all the answers given here but nothing worked as this issue is no more resolved just by using multiDexEnabled true. We can get the updated solution from this link. And don't forget to clean the project after this by using the command cd android && ./gradlew clean. As many of us still get the same error after implementing the solution. So it's a good practice to clean the project.

Aun Abbas
  • 540
  • 7
  • 18
1

Enabling Multidex at /android/app/build.gradle

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

dependencies {
  implementation 'androidx.multidex:multidex:2.0.1' //latest version
}

Extending MultiDexApplication at android/app/src/main/java/.../MainApplication.java

// ... all your other imports here
import androidx.multidex.MultiDexApplication; // add this import


// Your class definition needs `extends MultiDexApplication` like below
public class MainApplication extends MultiDexApplication implements ReactApplication {

source: https://rnfirebase.io/enabling-multidex

0

Add the below line to your android/build.gradle file

    ext {
            googlePlayServicesVersion = "16.0.1"
            // ... rest of ext properties
        }

https://github.com/idehub/react-native-google-analytics-bridge/wiki/Android-build-problems

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
Akhilesh Sinha
  • 861
  • 12
  • 20
0

me too had this same error, and i was able to debug it using the command ./gradlew assembleDebug --stacktrace(inside android folder) and for me it was because i had two libraries and both were having same package name, on changing package name of one resolved the issue

Jose Kj
  • 2,912
  • 2
  • 28
  • 40
  • can you check this https://stackoverflow.com/questions/59096566/execution-failed-for-task-apptransformdexarchivewithdexmergerfordebug-rea – Oliver D Nov 29 '19 at 00:32
0

Do this:

  1. Go to Android Studio

  2. Open your project file

  3. Click on Build

  4. Click on Clean Project

  5. Build again with react-native run-android

thatguy
  • 21,059
  • 6
  • 30
  • 40
hadi almosavi
  • 61
  • 1
  • 2