简体   繁体   English

任务“:app:transformDexArchiveWithDexMergerForDebug”执行失败。 - 反应本机

[英]Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'. - React Native

I have App written with react-native and it's work very fine previously but when I install RN async-storage .我有用 react-native 编写的应用程序,它以前工作得很好但是当我安装RN async-storage时。 I don't change anything in native android code我不更改本机 android 代码中的任何内容

I got an error when running the app.运行应用程序时出现错误。

I'm trying to remove it and rebuild my app BUT the issue still I don't know why!我正在尝试删除它并重建我的应用程序,但问题仍然存在,我不知道为什么!

I'm tried to run these command我试图运行这些命令

rm -rf node_modules 
npm install

then然后

cd android && gradlew clean

and it's building successfully without any error并且它正在成功构建而没有任何错误

but after run react-native run-android但在运行react-native run-android之后

I got我有

What went wrong: Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.出了什么问题:任务 ':app:transformDexArchiveWithDexMergerForDebug' 执行失败。 com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: The number of method references in a.dex file cannot exceed 64K. com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: The number of method references in a.dex 文件不能超过 64K。 Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.htmlhttps://developer.android.com/tools/building/multidex.html了解如何解决此问题

So how can I solve it?那么我该如何解决呢?

So here is the solution.所以这是解决方案。

First, let us solve the multiDex issue.In your myapp/android/app/build.gradle file, look for the block of code inside android and defaultConfig and then add the line multiDexEnabled true as shown below:首先,让我们解决 multiDex 问题。在您的myapp/android/app/build.gradle文件中,查找 android 和 defaultConfig 中的代码块,然后添加multiDexEnabled true行,如下所示:

android {
    ...

    compileOptions {
        ...
    }

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true //ADD THIS LINE 'multiDexEnabled true' Inside the defaultConfig code block
    }

}

Second, an effective way to clear npm is by first deleting node_modules folder and then running the command npm i and then npm start --reset-cache其次,清除 npm 的有效方法是先删除 node_modules 文件夹,然后运行命令npm i然后npm start --reset-cache

Third, an effective way to make a gradlew clean is by running this command cd android and then gradlew clean第三,使 gradlew 干净的有效方法是运行此命令cd android然后gradlew clean

After running these steps, you should be good to go.运行这些步骤后,您应该可以开始了。 All the best.祝一切顺利。

The right way to uninstall a npm package is卸载 npm 包的正确方法是

npm uninstall <name> --save

If you simply remove node_modules it wont be removed from package.json file, when u do npm install again the package will be installed if is not removed from package.json files moe detail here In the last line in the error log its mentioned as如果你简单地删除node_modules ,它不会从package.json文件中删除,当你再次执行 npm install 时,如果没有从package.json文件中删除,将安装包moe detail here在错误日志的最后一行中提到它

The number of method references in a.dex file cannot exceed 64K. .dex 文件中的方法引用数不能超过 64K。 Learn how to resolve this issue at to fix this error u might need to enable multidex as mentioned here了解如何解决此问题以修复此错误您可能需要启用此处提到的 multidex

It might be the minSdkVersion issue.可能是 minSdkVersion 的问题。 Try minSdkVersion = 21 at dir.在目录中尝试 minSdkVersion = 21。 android/build.gradle.安卓/build.gradle。

Follow this answer-按照这个答案-

https://stackoverflow.com/a/61341015/10638877 https://stackoverflow.com/a/61341015/10638877

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 任务 :app:transformClassesWithMultidexlistForDebug&#39; 执行失败。 反应本机 - Execution failed for task :app:transformClassesWithMultidexlistForDebug'. React Native React Native-任务&#39;:app:installDebug&#39;的执行失败 - React Native - Execution failed for task ':app:installDebug' 任务&#39;:app:compileDebugJavaWithJavac&#39;的执行失败反应本机 - Execution failed for task ':app:compileDebugJavaWithJavac' react native React Native-任务&#39;:app:compileDebugJavaWithJavac&#39;的执行失败 - React Native - Execution failed for task ':app:compileDebugJavaWithJavac' 任务':app:processDebugResources'的执行失败 - React Native - Execution failed for task ':app:processDebugResources' - React Native (React Native):任务 ':app:generatePackageList' 执行失败 - (React Native): Execution failed for task ':app:generatePackageList' react native中任务&#39;:app:transformClassesWithDexForDebug&#39;的执行失败 - Execution failed for task ':app:transformClassesWithDexForDebug' in react native React Native,任务&#39;:app:mergeDexDebug&#39;的执行失败 - React Native, Execution failed for task ':app:mergeDexDebug' 任务执行失败&#39;:app:processDebugManifest&#39; - React Native - Execution failed for task ':app:processDebugManifest' - React Native 任务 ':app:checkDebugDuplicateClasses' 执行失败。 反应原生 - Execution failed for task ':app:checkDebugDuplicateClasses'. React Native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM