任务':app:transformClassesWithDexForDebug'在本机中执行失败

时间:2017-10-16 16:05:25

标签: android react-native

我是react native中的新用户,我在Ubuntu中使用它。我想在我的电脑上运行一个项目。我使用纱线和android模拟器。这是我安装的应用程序版本:

yarn: 1.2.0

nmp: 3.10.10

使用时出现以下错误:

$ react-native run-android

这是错误:

  * 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

我已经测试了stackoverflow中存在的许多解决方案但是,它们中没有一个对我不起作用。如:

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

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

我也使用Google play service,我已经安装了Firebase插件。 你知道我该怎么办?

4 个答案:

答案 0 :(得分:8)

我的猜测是你超过了64k的参考限制,需要启用多索引。您链接的第二篇文章引用了如何解决此问题,但许多react-native项目使用16的minSdkVersion进行初始化,因此还有一个额外的步骤来启用multidex。你有两个选择。

选项1:

将您的minSdkVersion升级到AndroidManifest.xml文件(android / app / src / main / AndroidManifest.xml)以及build.gradle文件(android / app / build.gradle),然后放入build.gradle file在此行中将multiDexEnabled添加为true

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

选项2:

如果您需要保留minSdkVersion 16,请在build.gradle文件中将multiDexEnabled设置为true,然后在同一文件中的“dependencies”下添加此行

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

然后,根据您是否覆盖Application类,执行以下操作之一:

如果您没有覆盖Application类,请编辑清单文件以在标记中设置android:name,如下所示:

<?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>

如果你覆盖android / app / src / main / java / MainApplication.java中的Application类,请将其更改为扩展MultiDexApplication(如果可能),如下所示:

public class MyApplication extends MultiDexApplication { ... }

这是android的文档,说明此错误的含义及其发生的原因,以及如何修复它https://developer.android.com/studio/build/multidex.html

答案 1 :(得分:0)

这对我有用,当您在项目目录中时,请尝试使用:

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

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

答案 2 :(得分:0)

如果通过生成Release应用程序遇到此错误,则可以按照以下答案进行操作:-https://stackoverflow.com/a/57548822/9444013

答案 3 :(得分:0)

经过 2 个小时的搜索,此解决方案对我有用! cmd cd 安卓 然后 ./gradlew assembleDebug --stacktrace