Android studio Gradle build speed up

2019-01-01 14:42发布

Since the last update (Build from june 25) any changes in the Android studio Gradle is painfully slow. And it also seems to autotrack changes when you edit the file and recompile on keyup.

Each change takes several minutes on my i5.

Any idea how I can speed up my Gradle changes?

18条回答
明月照影归
2楼-- · 2019-01-01 14:52

There is a newer version of gradle (ver 2.4).

You can set this for your project(s) by opening up 'Project Structure' dialog from File menu,

Project Structure -> Project -> Gradle version

and set it to '2.4'.
You can read more about boosting performance at this link.

查看更多
一个人的天荒地老
3楼-- · 2019-01-01 14:54

You can also use command line for better performance.You can use the command ./gradlew <task name> from inside the root folder of your project from linux or use gradlew.bat file like gradlew <task name>.when you first run one of the commands above for a given Gradle version, it will download the corresponding Gradle distribution and use it to execute the build.

When importing a Gradle project via its wrapper, your IDE may ask to use the Gradle 'all' distribution. This is perfectly fine and helps the IDE provide code completion for the build files. Not only does this mean that you don’t have to manually install Gradle yourself, but you are also sure to use the version of Gradle that the build is designed for. This makes your historical builds more reliable. for more info refer Executing a build with the Wrapper

查看更多
姐姐魅力值爆表
4楼-- · 2019-01-01 14:54

For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.

To do this set
org.gradle.jvmargs=-Xmx2048M
in the project gradle.properties.

查看更多
深知你不懂我心
5楼-- · 2019-01-01 14:55

With Android Studio 2.1 you can enable "Dex In Process" for faster app builds.

enter image description here

You can get more info about it here: https://medium.com/google-developers/faster-android-studio-builds-with-dex-in-process-5988ed8aa37e#.vijksflyn

查看更多
步步皆殇っ
6楼-- · 2019-01-01 15:01

After change this settings my compile time 10 mins reduced to 10 secs.

Step 1:

Settings(ctrl+Alt+S) ->

Build,Execution,Deployment ->

Compiler ->

type "--offline" in command-line Options box.

Step 2:

check the “Compile independent modules in parallel” checkbox.

& click Apply -> OK

enter image description here

Step 3: In your gradle.properties file -> Add following lines

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

Update:

If you are using Android studio 2.0 or above try the Instant Run

Settings → Build, Execution, Deployment → Instant Run → Enable Instant Run.

More info about Instant Run - https://developer.android.com/studio/run/index.html#instant-run

查看更多
爱死公子算了
7楼-- · 2019-01-01 15:02

Try to avoid using a Mac/PC that has only 8 GB of RAM when doing Android development. As soon as you launch even 1 emulator (Genymotion or otherwise), your build times become extremely slow in Android Studio with gradle builds. This happens even if you make a simple one-line change to 1 source file.

Closing the emulator and using a real device helps a lot, but of course this is very limiting and less flexible. Reducing the RAM usage setting of the emulator can help, but the best way is to ensure your laptop has at least 12-16 GB of RAM.

Update (June 2017): There are now several good medium.com articles that explain how to speed up Android Studio gradle builds in detail, and it even works on 8 GB machines:

The summarised consensus is:

Create a gradle.properties file (either global at ~/.gradle/gradle.properties or local to project), and add the following lines:

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
查看更多
登录 后发表回答