我已经升级到Android Studio 2.1,并且在尝试构建和运行公司的大型项目时遇到此错误:
任务':app:transformClassesWithDexForMyAppDebug'的执行失败。com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:java.util.concurrent.ExecutionException:java.lang.OutOfMemoryError:超出了GC开销限制
我已经搜索了整个论坛并禁用了即时运行,还写了我的build.gradle:
dexOptions {
incremental true
javaMaxHeapSize "6g"
}
...
dependencies{
compile 'com.android.support:multidex:'
}
但这并不能解决我的问题。我在gradle中启用了multidex,因为没有它就会出现错误:
com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中:65536
因此,这是解决方案,它在以前版本的Android Studio(也适用于公司中其他使用Android Studio 1.4-2.0的版本)上运行过,但不适用于我,因为我升级了Android Studio。
有谁知道会导致问题的原因吗?
有趣的是,如果我只是创建项目,则只有在尝试运行它时,我才不会收到错误消息。任何想法表示赞赏!
编辑1:
有趣的是,如果我重新启动android studio,则第一次运行成功,但是第二次失败。
编辑2:
如果我将堆大小设置为大于应用程序大小(例如8-10g),则即使在第一次运行时也无法编译。
编辑3:
似乎问题在于即时运行,如果我强迫android studio不使用它(例如一次部署到两个设备或更改gradle.properties,如答案中所示),该错误就会消失。
将此添加到您的gradle.properties
文件。
# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
org.gradle.daemon=true
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
# Enables new incubating mode that makes Gradle selective when configuring projects.
# Only relevant projects are configured which results in faster builds for large multi-projects.
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:configuration_on_demand
org.gradle.configureondemand=true
在这里找到
而在我的build.gradle
:
....
dexOptions
{
incremental false
javaMaxHeapSize "2048M"
preDexLibraries = false
}//end dexOptions
....
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句