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

时间:2021-08-20 20:51:35

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:进程'命令'C:\ Program Files \ Java \ jdk1.8.0_05 \ bin \ java.exe''以非零退出值2结束

10 个解决方案

#1


54  

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 executable and Building Apps with Over 65K Methods

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

#2


13  

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

在我的情况下使用android studio 2.0预览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 \程序\编译\中间体

and run the application and it works.

并运行应用程序,它的工作原理。

#3


4  

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工作室,在我关闭2后我没有得到任何错误。

No need to add any code related to multiDex !

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

Seems like there was some memory issue related to jvm.

好像有一些与jvm相关的内存问题。

#4


4  

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

#5


1  

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

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

#6


0  

Add the following line:

添加以下行:

multiDexEnabled true

Inside the defaultConfig of build.gradle

在build.gradle的defaultConfig中

Like this:

喜欢这个:

defaultConfig{
    multiDexEnabled true
}

#7


0  

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”,解决问题。这将解决问题,特别是如果您使用的旧版Android Studio低于版本2。

#8


0  

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

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

minSdkVersion 21

minSdkVersion 21

targetSdkVersion 25

targetSdkVersion 25

multiDexEnabled true

multiDexEnabled是的

works fine.

工作正常。

#9


0  

in my case - Clean Project and Rebuild

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

#10


0  

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之间来回反复本地化。世博会需要一个应用程序名称才能构建,Android Studio需要另一个,一旦我把它放回到android工作室想要它构建和部署的名称。

Expo

世博会

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

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

Android Studio

Android Studio

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

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

#1


54  

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 executable and Building Apps with Over 65K Methods

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

#2


13  

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

在我的情况下使用android studio 2.0预览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 \程序\编译\中间体

and run the application and it works.

并运行应用程序,它的工作原理。

#3


4  

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工作室,在我关闭2后我没有得到任何错误。

No need to add any code related to multiDex !

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

Seems like there was some memory issue related to jvm.

好像有一些与jvm相关的内存问题。

#4


4  

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

#5


1  

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

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

#6


0  

Add the following line:

添加以下行:

multiDexEnabled true

Inside the defaultConfig of build.gradle

在build.gradle的defaultConfig中

Like this:

喜欢这个:

defaultConfig{
    multiDexEnabled true
}

#7


0  

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”,解决问题。这将解决问题,特别是如果您使用的旧版Android Studio低于版本2。

#8


0  

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

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

minSdkVersion 21

minSdkVersion 21

targetSdkVersion 25

targetSdkVersion 25

multiDexEnabled true

multiDexEnabled是的

works fine.

工作正常。

#9


0  

in my case - Clean Project and Rebuild

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

#10


0  

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之间来回反复本地化。世博会需要一个应用程序名称才能构建,Android Studio需要另一个,一旦我把它放回到android工作室想要它构建和部署的名称。

Expo

世博会

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

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

Android Studio

Android Studio

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

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