【问题标题】:React Native: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'React Native:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败
【发布时间】:2018-07-09 06:34:17
【问题描述】:

我已经尝试过 gradlew clean 以及此处和 GitHub 上可用的所有其他解决方案,但错误不匹配并且解决方案不起作用

运行react-native run-android后出现cmd错误

 > 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

我已经尝试了所有的解决方案,但似乎都没有奏效。请帮忙

react-native-cli:2.0.1
反应原生:0.53.0


build.gradle 文件:

// 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 文件:

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'
}

编辑

multidexEnabled = true 添加到android/app/build.gradle 文件后 弹出以下错误:

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

这个错误在任何地方都没有得到回答,所以我把它作为这个问题的更新。

【问题讨论】:

  • 请添加您的android/app/build.gradle,假设您已退出。
  • 添加了@JohannaLarsson
  • 你能分享一下你是怎么解决的吗?我也遇到了

标签: react-native


【解决方案1】:

几天前遇到同样的错误,看来您必须启用 multidex 为 true 并删除构建文件夹。

转到android/app/build.gradle 并添加行multiDexEnabled true 并在defaultConfig 中将minSdkVersion 设置为21,如下所示

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

你可以在 react-native 上查看这个帖子

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

【讨论】:

  • 在哪里启用这个?我试过删除和弹出/android,它不起作用(github上的解决方案)
  • 在你的模块级 build.gradle 文件中。像这样的东西:android { defaultConfig { ... minSdkVersion 21 targetSdkVersion 26 multiDexEnabled true } ... }
  • 请将您的android/app/build.gradle 文件添加到您的问题中
  • 更改您的 minSdkVersion to 21 并在下一行添加 multiDexEnabled true 即在您的 android/app/build.gradle 文件中阅读更多有关此内容的信息 developer.android.com/studio/build/multidex#mdex-gradle
  • 它在 react-native-cli 上为我工作而无需更改 minSdkVersion,只是添加了multiDexEnabled true 行,它就像一个魅力。谢谢!
【解决方案2】:

我已通过在 /android/app/build.gradle 文件中启用 multiDex 来修复。

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

【讨论】:

【解决方案3】:

打开 /android/app/build.gradle 文件。

在依赖项下我们需要添加模块,然后在defaultConfig中启用它

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

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

【讨论】:

  • 太棒了。我可以确认这适用于"react-native": "0.62.2"。谢谢
【解决方案4】:

我通过启用解决问题

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

路径:android/app/build.gradle

【讨论】:

    【解决方案5】:

    将关注添加到您的android/app/build.gradle

    dependencies {
       ....
       implementation 'com.android.support:design:27.1.0'
       ....
    }
    

    【讨论】:

      【解决方案6】:

      我遇到了这个错误

      任务“:app:multiDexListDebug”执行失败。

      但他在我的错误的延续中写道

      我从两个地址安装了异步存储 当我删除第二个

      错误已修复

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

      【讨论】:

      • 我的情况是蒙面视图 @react-native-masked-view/masked-view@react-native-community/masked-view
      【解决方案7】:

      这将解决它 cd android && ./gradlew clean

      【讨论】:

        【解决方案8】:

        您可能必须将multiDexEnabled true 属性添加到您的android/app/build.gradle 文件中。

        defaultConfig {
            multiDexEnabled true
        
            // (...) more properties
        }
        

        控制台错误提示您克服此问题。他们向您展示了这个链接:https://developer.android.com/studio/build/multidex

        您可以在此处了解有关该问题的更多信息。但这是我在 2020 年的解决方案。和平!

        【讨论】:

          【解决方案9】:
          At Path android/app/build.gradle
          
          defaultConfig {
          multiDexEnabled true //Add this line
          }
          

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

          【讨论】:

            【解决方案10】:

            作为此答案的更新(如果人们无法弄清楚原因,尤其是一台 Mac)

            使用须藤!我试图弄清楚为什么 gradlew 命令没有运行很长时间,结果证明 - 它没有权限!

            用途:

            sudo ./gradlew [command]

            我既沮丧又高兴。

            【讨论】:

            【解决方案11】:

            我也有同样的问题。所以为了让它“更清楚”,我做了这些:

            1. 更新到 sdk27(编译和目标)。 minSdk 在 21
            2. 将相关的 goodle-play 基地/服务/地图更新到 15.0.1(取决于您的项目要求)
            3. 然后:我在上面没有(1)的同一部分添加multidexEnabled=true
            4. (可选)- 我遇到了 Gradle 无法正确找到播放服务版本的另一个问题:我修改了项目 build.gradle 以在 jcenter() 之前先搜索 google maven

              maven {
                  url 'https://maven.google.com/'
                  name 'Google'
              }
              mavenLocal()
              jcenter()
              

            【讨论】:

              【解决方案12】:

              在文件 (<your_project_folder>/android/app/build.gradle) 中,用以下几行修改代码:

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

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

              【讨论】:

                【解决方案13】:

                快跑

                cd android && gradlew clean
                

                然后

                cd .. && react-native run-android
                

                【讨论】:

                  【解决方案14】:

                  必须使用最新的 dex 版本

                  implementation 'androidx.multidex:multidex:2.0.1'
                  

                  【讨论】:

                  • 这是反应原生的正确推荐答案
                  【解决方案15】:

                  我尝试了此处给出的所有答案,但没有任何效果,因为仅使用 multiDexEnabled true 就无法解决此问题。 我们可以从这个link 获得更新的解决方案。在此之后不要忘记使用命令cd android && ./gradlew clean 清理项目。因为我们中的许多人在实施解决方案后仍然会遇到同样的错误。所以清理项目是一个好习惯。

                  【讨论】:

                    【解决方案16】:

                    我也有同样的错误,我可以使用命令./gradlew assembleDebug --stacktrace(在 android 文件夹内)对其进行调试,对我来说这是因为我有两个库,并且在更改包名时都有相同的包名一个解决了这个问题

                    【讨论】:

                    【解决方案17】:

                    将以下行添加到您的 android/build.gradle 文件中

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

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

                    【讨论】:

                      【解决方案18】:

                      这样做:

                      1. 转到 Android Studio

                      2. 打开你的项目文件

                      3. 点击构建

                      4. 点击清理项目

                      5. 使用react-native run-android再次构建

                      【讨论】:

                        猜你喜欢
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 1970-01-01
                        • 2018-05-08
                        • 2019-02-15
                        • 1970-01-01
                        • 2022-11-08
                        • 2021-07-09
                        相关资源
                        最近更新 更多