Java Android Studio TransformException:错误:任务':app:transformClassesWithDexForDebug'的执行失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33915955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 15:08:36  来源:igfitidea点击:

Android Studio TransformException : Error:Execution failed for task ':app:transformClassesWithDexForDebug'

javaandroidandroid-studio

提问by Shobharam Piplode

I am getting the exception below when I am trying to run the application using Android Studio:

当我尝试使用 Android Studio 运行应用程序时,出现以下异常:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_05\bin\java.exe'' finished with non-zero exit value 2

错误:任务“:app:transformClassesWithDexForDebug”的执行失败。com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_05 \bin\java.exe'' 以非零退出值 2 结束

回答by Danh DC

I have same issue, after few hour research, i found a solution to fix it.

我有同样的问题,经过几个小时的研究,我找到了解决方案。

You should fixed build.gradle:

你应该修复build.gradle

android {

    compileSdkVersion ..
    buildToolsVersion '...'

    defaultConfig {
       ...
       targetSdkVersion ..
       multiDexEnabled true  // this line will solve this problem
   }
}

If the number of method references in your app exceeds the 65K limit, your app may fail to compile.

如果您的应用程序中的方法引用数量超过 65K 限制,您的应用程序可能无法编译。

For information on how to do this, see Selectively compiling APIs into your executableand Building Apps with Over 65K Methods

有关如何执行此操作的信息,请参阅有选择地将 API 编译为可执行文件使用超过 65K 的方法构建应用程序

回答by humazed

in my case using android studio 2.0 preview 4 I suddenly got that problem and adding multiDexEnabled truedidn't help, and also clean and rebuilt didn't help.

在我使用 android studio 2.0 preview 4 的情况下,我突然遇到了这个问题,添加 multiDexEnabled true没有帮助,而且清理和重建也没有帮助。

so the only thing that solved it for me is deleting that file:

所以唯一为我解决的就是删除那个文件:

YOUR_APP_NAME\app\build\intermediates

YOUR_APP_NAME\app\build\intermediates

and run the application and it works.

并运行该应用程序,它可以工作。

回答by Sanyam Jain

For me closing all other Android Studio solved the problem.

对我来说,关闭所有其他 Android Studio 解决了这个问题。

I had opened 3 android studios when I was getting the error, after I closed 2 I didn't get any error.

出现错误时,我打开了 3 个 android studio,关闭 2 个后我没有收到任何错误。

No need to add any code related to multiDex !

无需添加任何与 multiDex 相关的代码!

Seems like there was some memory issue related to jvm.

似乎存在一些与 jvm 相关的内存问题。

回答by Dr. Failov

Just fixed this issue. In my case, rebuilding the project helped for me. So, try to rebuild your project.

刚刚修复了这个问题。就我而言,重建项目对我有帮助。因此,尝试重建您的项目。

回答by Mohamed Ibrahim

Add the following line:

添加以下行:

multiDexEnabled true

Inside the defaultConfigof build.gradle

里面defaultConfigbuild.gradle

Like this:

像这样:

defaultConfig{
    multiDexEnabled true
}

回答by ankush

Modify the module-level build.gradle file

修改模块级 build.gradle 文件

 android {
    ...

    // Enabling multidex support.
    multiDexEnabled true
}
...

}

}

add dependencies compile 'com.android.support:multidex:1.0.0'

添加依赖项编译 'com.android.support:multidex:1.0.0'

In your manifest add the MultiDexApplication class

在您的清单中添加 MultiDexApplication 类

<manifest ...>
<application
    ...
    android:name="android.support.multidex.MultiDexApplication">
    ...
</application>

http://developer.android.com/studio/build/multidex.html

http://developer.android.com/studio/build/multidex.html

回答by Ayman Mahgoub

At my case change buildToolsVersion from "24" to "23.0.2", solve the problem. This will solve the problem especially if you're using old Android Studio less than version 2.

在我的情况下,将 buildToolsVersion 从“24”更改为“23.0.2”,解决问题。这将解决问题,特别是如果您使用的是低于版本 2 的旧 Android Studio。

回答by Hymany wang

I found the answer from here: After change the build.gradefile with the following

我从这里找到了答案:build.grade使用以下内容更改文件后

minSdkVersion 21

targetSdkVersion 25

multiDexEnabled true

minSdk 版本 21

目标SDK版本25

multiDexEnabled true

works fine.

工作正常。

回答by NataTse

in my case - Clean Project and Rebuild

在我的情况下 - 清理项目和重建

回答by Brandon S?ren Culley

In my case I was going back and forth between Expo and Android Studio for react native. Expo wanted one application name in order to build and Android Studio wanted another, once I put it back to the name that android studio wanted it built and deployed fine.

就我而言,我在 Expo 和 Android Studio 之间来回切换原生反应。Expo 需要一个应用程序名称以便构建,而 Android Studio 需要另一个应用程序名称,一旦我将其恢复为 android studio 希望它构建和部署正常的名称。

Expo

世博会

AppRegistry.registerComponent('main', () => App);

AppRegistry.registerComponent('main', () => App);

Android Studio

安卓工作室

AppRegistry.registerComponent('AwesomeProject', () => App);

AppRegistry.registerComponent('AwesomeProject', () => App);