1

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.

Ankur Khandelwal
  • 1,042
  • 3
  • 19
  • 40

4 Answers4

2

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

Uddhav P. Gautam
  • 7,362
  • 3
  • 47
  • 64
Prashant Jajal
  • 3,469
  • 5
  • 24
  • 38
  • No help.. getting same time. – Ankur Khandelwal Nov 07 '16 at 11:33
  • then may be your system configuration is low. and android studio required more RAM min 4 gb. if you have 8gb then its better. and processor more then core-i5. – Prashant Jajal Nov 07 '16 at 11:35
  • 1
    system configuration:- 8GB RAM and core- i5 – Ankur Khandelwal Nov 07 '16 at 11:37
  • i also facing this same issue. when i start computer at morning its work fine for 3 4 hour. but after that its taking too much time for gradle building. may be need to format pc or change hdd to ssd hard disk. i have also same configuration as you mention. – Prashant Jajal Nov 07 '16 at 11:40
  • somewhere i here that. if we have SSd hard disk then its work too much fast for any kind of processing. work fast on speed of 10x compare to hdd. – Prashant Jajal Nov 07 '16 at 11:45
  • if build is taking more than 30min, try **gradle offline mode** . android_studio 3.6 and above https://stackoverflow.com/questions/57797772/cannot-enable-gradles-offline-mode-on-android-studio-3-6 – bh_earth0 Nov 10 '22 at 13:13
2

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.

Zhang Xiang
  • 422
  • 4
  • 15
1

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

Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77
0

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
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428