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

Sho*_*ode 45 java android android-studio

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

错误:任务':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结束

Dan*_* DC 57

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

你应该修复build.gradle:

android {

    compileSdkVersion ..
    buildToolsVersion '...'

    defaultConfig {
       ...
       targetSdkVersion ..
       multiDexEnabled true  // this line will solve this problem
   }
}
Run Code Online (Sandbox Code Playgroud)

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

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


hum*_*zed 13

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

所以解决它的唯一问题是删除该文件:

YOUR_APP_NAME \程序\编译\中间体

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


ank*_*ush 5

修改模块级别的build.gradle文件

 android {
    ...

    // Enabling multidex support.
    multiDexEnabled true
}
...
Run Code Online (Sandbox Code Playgroud)

}

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

在清单中添加MultiDexApplication类

<manifest ...>
<application
    ...
    android:name="android.support.multidex.MultiDexApplication">
    ...
</application>
Run Code Online (Sandbox Code Playgroud)

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