Ankur Khandelwal
Ankur Khandelwal

Reputation: 1070

Why my gradle building taking too much time?

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.

Upvotes: 2

Views: 13334

Answers (5)

Thiamath
Thiamath

Reputation: 71

In case you just landed here recently and the above solutions:

  • Increase memory
  • Put Gradle in offline mode
  • Tweak Gradle settings

and you are still suffering a very slow building (usually the first one), and you are using Windows OS, I suggest you try to temporarily disable the Real-Time Protection system from Windows Defender until it finishes the building.

It is very snoopy regarding processes that download files and can interfere with Gradle building.

Of course... be careful if the project you are building is not coming from a trustworthy source... use this tip at your own risk. Since the first building is usually when you are kickstarting a new project, it should be safe enough.

Upvotes: 1

Prashant Jajal
Prashant Jajal

Reputation: 3627

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.

Note: In newer version of Android studio, View->Tool Windows->Gradle->Toggle button of online/offline

Upvotes: 3

Zhang Xiang
Zhang Xiang

Reputation: 432

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.

Upvotes: 3

Manoj Perumarath
Manoj Perumarath

Reputation: 10214

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

Upvotes: 1

EpicPandaForce
EpicPandaForce

Reputation: 81539

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

Upvotes: 2

Related Questions