12

In the "old days", the build tool knew when it had and didn't have to rebuild an application by looking at the time stamps of the individual source files. Why does Gradle, the most modern tool for building Android application, use 17 seconds in my case to do god knows what, before deplyoing and launching an app that is not changed since last build?

The first 8 seconds seems to be spent on building the build script ("Configuring")

The next 9 seconds is spent on running the following task:

:app:preBuild
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:library:compileLint
:library:copyReleaseLint UP-TO-DATE
:library:mergeReleaseProguardFiles UP-TO-DATE
:library:preBuild
:library:preReleaseBuild
:library:checkReleaseManifest
:library:preDebugBuild
:library:preDebugTestBuild
:library:prepareComAndroidSupportAppcompatV71910Library UP-TO-DATE
:library:prepareComGoogleAndroidGmsPlayServices3265Library UP-TO-DATE
:library:prepareReleaseDependencies
:library:compileReleaseAidl UP-TO-DATE
:library:compileReleaseRenderscript UP-TO-DATE
:library:generateReleaseBuildConfig UP-TO-DATE
:library:generateReleaseAssets UP-TO-DATE
:library:mergeReleaseAssets
:library:processReleaseManifest UP-TO-DATE
:library:crashlyticsCleanupResourcesRelease
:library:crashlyticsUploadStoredDeobsRelease
:library:crashlyticsGenerateResourcesRelease
:library:generateReleaseResValues UP-TO-DATE
:library:generateReleaseResources UP-TO-DATE
:library:mergeReleaseResources
:library:processReleaseResources
:library:generateReleaseSources
:library:compileReleaseJava UP-TO-DATE
:library:processReleaseJavaRes UP-TO-DATE
:library:packageReleaseJar UP-TO-DATE
:library:compileReleaseNdk UP-TO-DATE
:library:packageReleaseJniLibs UP-TO-DATE
:library:packageReleaseLocalJar UP-TO-DATE
:library:packageReleaseRenderscript UP-TO-DATE
:library:packageReleaseResources
:library:bundleRelease
:app:prepareComAndroidSupportAppcompatV71910Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices5089Library UP-TO-DATE
:app:prepareComMixpanelAndroidMixpanelAndroid431Library UP-TO-DATE
:app:prepareVGSwipelibraryUnspecifiedLibrary
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:processDebugManifest UP-TO-DATE
:app:crashlyticsCleanupResourcesDebug
:app:crashlyticsUploadStoredDeobsDebug
:app:crashlyticsGenerateResourcesDebug
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources
:app:processDebugResources
:app:generateDebugSources
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug UP-TO-DATE
:app:crashlyticsStoreDeobsDebug
:app:crashlyticsUploadDeobsDebug
:app:crashlyticsCleanupResourcesAfterUploadDebug
:app:compileDebugNdk UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug
:app:zipalignDebug
:app:assembleDebug
:library:copyDebugLint UP-TO-DATE
:library:mergeDebugProguardFiles UP-TO-DATE
:library:checkDebugManifest
:library:prepareDebugDependencies
:library:compileDebugAidl UP-TO-DATE
:library:compileDebugRenderscript UP-TO-DATE
:library:generateDebugBuildConfig UP-TO-DATE
:library:generateDebugAssets UP-TO-DATE
:library:mergeDebugAssets
:library:processDebugManifest UP-TO-DATE
:library:crashlyticsCleanupResourcesDebug
:library:crashlyticsUploadStoredDeobsDebug
:library:crashlyticsGenerateResourcesDebug
:library:generateDebugResValues UP-TO-DATE
:library:generateDebugResources UP-TO-DATE
:library:mergeDebugResources
:library:processDebugResources
:library:generateDebugSources
:library:compileDebugJava UP-TO-DATE
:library:processDebugJavaRes UP-TO-DATE
:library:packageDebugJar UP-TO-DATE
:library:compileDebugNdk UP-TO-DATE
:library:packageDebugJniLibs UP-TO-DATE
:library:packageDebugLocalJar UP-TO-DATE
:library:packageDebugRenderscript UP-TO-DATE
:library:packageDebugResources
:library:bundleDebug
:library:crashlyticsStoreDeobsDebug
:library:crashlyticsUploadDeobsDebug
:library:crashlyticsCleanupResourcesAfterUploadDebug
:library:assembleDebug

What happened? Why does I as a developer need to spend 17 seconds waiting for the build system to determine that nothing has changed?

Is there hacks to work around this shortcoming, so that when I simply want to relaunch my app from Android Studio I don't need to wait for it to recompile?

I know I can create a Run configuration where I remove the "Make" step, but then the process of determining whether anything is changed or not, is left up to me as a developer to decide. I don't think that's an acceptable solution.

Nilzor
  • 18,082
  • 22
  • 100
  • 167
  • I find this rather frustrating too. I've started a bounty in the hopes someone can provide a solution. – Duncan Jones Dec 22 '14 at 06:38
  • 3
    Do any the responses to [this Stack Overflow question](http://stackoverflow.com/questions/16775197/building-and-running-app-via-gradle-and-android-studio-is-slower-than-via-eclips) help? – Joel Dec 22 '14 at 14:00
  • The later versions of the plugin and gradle has definitely helped, along with the configurations suggested in your thread Joel. There is still a long way to go to Eclipse or Idea/Maven standards though. I still don't understand why *any* compiling/dexing has to be done when no changes have been made. – Nilzor Dec 22 '14 at 14:27

1 Answers1

4

Use gradle daemon, configure it using gradle.properties.

The Gradle daemon (sometimes referred as the build daemon) aims to improve the startup and execution time of Gradle

Gradle is java based tool. Most of the time is spent starting JVM. Your 8 and 9 seconds are due to Java Compiling and JVM starting. Gradle daemon will offset these issues.

TL;DR; Gradle daemon will make your builds a lot faster.

Add gradle.properties file to same folder as your build.gradle. Add following property this file.

org.gradle.daemon=true

See two runs of gradle

P:\github\WekaExamples>gradle
:help

Welcome to Gradle 2.2.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

BUILD SUCCESSFUL

Total time: 14.545 secs
P:\github\WekaExamples>gradle
:help

Welcome to Gradle 2.2.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

BUILD SUCCESSFUL

Total time: 3.578 secs

Second one is a lot faster due to gradle daemon.

Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69
  • Please provide a sample grade.properties instead of just linking to the documentation. Yes, i am bit pressed for time to deep learn this. – appbootup Dec 26 '14 at 07:53
  • @SSR added example gradle.properties file – Atilla Ozgur Dec 27 '14 at 20:43
  • 4
    This solves half of the problem, and I'm grateful for the input. The remaining half is still the issue of gradle (or the android-gradle plugin) spending too much time on determining that the project is unchanged. Your example does not perform any task, so it completes in 3.578 secs. That would not be close to the case when you execute the task "assembleDebug" (on the second run) – Nilzor Dec 29 '14 at 15:03