Why my gradle building taking too much time?

2019-09-07 05:06发布

问题:

I am developing the app which has apk size 28 MB. What should I do so that I take less time.

If I run on emulator than it takes 5-7 mins but if I run it on device than it is taking more than 10 min.

回答1:

you can set file->setting->search 'Gradle'-> check 'use local gradle distribution' and check 'offline work'.. in android studio. it will improve gradel building time.



回答2:

I too had this issue, what i had done was disabling instant run in the project settings, and rebuilding the project.



回答3:

If you are developing on Windows, then you should open Control Panel -> Windows Defender, then go to Settings -> Excluded Files and Locations -> Browse, and add your project library (including the build folder), and C:\Users\YourUser\.gradle


Also, add following to gradle.properties in your project:

org.gradle.jvmargs = -Xms2048m -Xmx4096m -XX:MaxPermSize=1024m -XX:ReservedCodeCacheSize=1024m


回答4:

There are some tips for reducing your build time: In your /.gradle/gradle.properties file :

# 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
org.gradle.parallel=true
org.gradle.configureondemand=true

And you can disable the lint task when you build your project,add the task in your build.gradle file:

tasks.whenTaskAdded { task ->
    if (task.name.equals("lint")) {
        task.enabled = false
    }
}

It is really useful for me! Hope it can help you!

Before reducing the building time, you should find out which step cost too much time.

./gradlew assembleDebug --dry-run --profile

It will product a report about the work of building in build/reports/profile/ direction, just read the report then to optimize your build work.