我的Android Studio项目过去构建得更快,但现在需要很长时间来构建。知道是什么导致了延误吗?
我试过https://stackoverflow.com/a/27171878/391401但没有效果。我没有运行任何可能中断构建的反病毒程序。我的应用程序也没有那么大(大约5MB),它曾经在几秒钟内构建,但不确定发生了什么变化。
10:03:51 Gradle build finished in 4 min 0 sec
10:04:03 Session 'app': running
10:10:11 Gradle build finished in 3 min 29 sec
10:10:12 Session 'app': running
10:20:24 Gradle build finished in 3 min 42 sec
10:28:18 Gradle build finished in 3 min 40 sec
10:28:19 Session 'app': running
10:31:14 Gradle build finished in 2 min 56 sec
10:31:14 Session 'app': running
10:38:37 Gradle build finished in 3 min 30 sec
10:42:17 Gradle build finished in 3 min 40 sec
10:45:18 Gradle build finished in 3 min 1 sec
10:48:49 Gradle build finished in 3 min 30 sec
10:53:05 Gradle build finished in 3 min 22 sec
10:57:10 Gradle build finished in 3 min 19 sec
10:57:11 Session 'app': running
找到了一个简单和最好的方法来构建gradle
去你的应用>>打开gradle。属性,并更改一些行从它[remove #]
否则你可以复制粘贴我下面的片段以及
# 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: -Xmx2048m -XX:MaxPermSize=512m
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -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
以前对我来说很有效,大约需要2-3分钟,现在只需要5-6秒
在上面的场景中,我的mac机器有8GB内存,所以我为gradle分配了4gb内存