Android Studio Gradle build running问题解决方法

1,991 阅读2分钟

升级Android Studio到最新版本,手欠啊!!!正常运行的项目,突然运行不了了

不过启动画面不错,这是一只小狐狸吗?

image.png

虽然长的好看,有毛线用啊,导致正在运行的工程突然启动不了(不是时间长啊) Gradle build running running running ...... ,一直在running..., how???

方案一:本工程生效

在model工程下添加gradle.property文件,并在gradle.property文件中添加如下代码:

org.gradle.daemon=true
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.configureondemand=true

完整版解释:


# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.

# For more details on how to configure your build environment visit
#http://www.gradle.org/docs/current/userguide/build_environment.html

# 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.
# TODO: disable daemon on CI, since builds should be clean and reliable on servers
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


这种方法的作用范围是本项目工程,其他项目工程如果也遇到gradle build running慢或者一直running的问题,可尝试用同样的方法尝试。

方案二:ide生效

修改android studio配置,在android studio的配置中,开启offline模式,以及修改配置。实际上的配置和上面的一大段一样,主要是在这个地方配置的只会在ide构建的时候生效,命令行构建不会生效。

方案三:全局生效

开启全局gradle单独的守护进程,在如下目录新建文件gradle.property

* /home/<username>/.gradle/ (Linux) 
* /Users/<username>/.gradle/ (Mac) 
* C:\Users\<username>\.gradle (Windows)

文件中增加: org.gradle.daemon=true

其他优化方法同方案一,只不过配置在次目录下会对所有项目生效。