Roh*_*ati 74 android android-studio gradle-daemon
每次运行我的应用程序时,我都会收到此Gradle错误.错误是:
要在进程中运行dex,Gradle守护程序需要更大的堆.它目前有大约910 MB.
要加快构建速度,请将Gradle守护程序的最大堆大小增加到2048 MB以上.
为此,请在项目gradle.properties中设置org.gradle.jvmargs = -Xmx2048M.有关更多信息,请参阅https://docs.gradle.org/current/userguide/build_environment.html
这是我的build.gradle(Module:app)文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "mobileapp.tech2dsk"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
}
Run Code Online (Sandbox Code Playgroud)
这是我的build.gradle(Project)文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
这是我的gradle.properties文件:
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# 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
Run Code Online (Sandbox Code Playgroud)
Vee*_*ath 50
添加Build.gradle
android {
dexOptions {
javaMaxHeapSize "4g"
}
}
Run Code Online (Sandbox Code Playgroud)
更多信息 - Android Gradle:什么是javaMaxHeapSize"4g"?
Sot*_*tti 47
2017年6月25日更新
在Google IO 2017上,有一些关于此主题的更新.不建议在dexOptions上设置标志,所以如果你有类似下一个的东西,你可以删除它.
dexOptions {
javaMaxHeapSize "2g"
}
Run Code Online (Sandbox Code Playgroud)
原始答案:
Android Studio 2.1支持Dex In Process,它与Gradle共享VM以缩短构建时间.因此,有必要增加Gradle守护程序的大小以合并这些Dex进程.
至少它需要2演出的内存,但如果你能负担得起,你可以尝试三个.
gradle.properties.
org.gradle.jvmargs=-Xmx3072m
Run Code Online (Sandbox Code Playgroud)
默认情况下,Java最大堆大小是一个gig,但是如果你在build.gradle文件上修改它...
build.gradle(App)
dexOptions {
javaMaxHeapSize "2g"
}
Run Code Online (Sandbox Code Playgroud)
...你必须相应地调整Gradle守护进程大小(必须更大以适应堆).
笔记:
luj*_*jop 21
只需将其保留在gradle.properties上:
org.gradle.jvmargs=-Xmx2048m
Run Code Online (Sandbox Code Playgroud)
您可以查看该文章作为参考.
Aja*_*dya 13
我知道答案为时已晚,但希望对某人有所帮助
我已经尝试了很多东西和搜索很多,但没有任何作品对我来说包括以下和gradle.properties也不适用于我的情况
android {
dexOptions {
javaMaxHeapSize "4g"
}
}
Run Code Online (Sandbox Code Playgroud)
您还可以在gradle.properties上尝试添加:
org.gradle.jvmargs=-Xmx2048m
Run Code Online (Sandbox Code Playgroud)
在我的情况下,问题是CPU利用有很多进程运行,而我构建apk我只是杀死一些进程,如genymotion,skype,safari等,而无效的缓存/重启它对我有用.
小智 5
在以下目录中修改或创建一个名为gradle.properties的文件。
对于Mac,是/Users/USER_NAME/.gradle/gradle.properties
对于Linux,/home/USER_NAME/.gradle/gradle.properties
对于Windows,C:\ Users \ USER_NAME.gradle \ gradle.properties
并应用以上更改。最后看起来应该像
org.gradle.daemon=true
# 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
org.gradle.configureondemand=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
Run Code Online (Sandbox Code Playgroud)
请参考此链接 https://tausiq.wordpress.com/2015/02/24/android-speed-up-gradle-build-process-in-android-studio/
| 归档时间: |
|
| 查看次数: |
48585 次 |
| 最近记录: |