为什么Android Studio / Gradle在没有进行任何更改时重建我的应用程序?

时间:2014-11-07 11:58:34

标签: intellij-idea gradle android-studio

在“过去的日子”中,构建工具知道它何时具有并且不必重建应用程序     查看各个源文件的时间戳。为什么Gradle是最现代化的工具     对于构建Android应用程序,在我的情况下使用17秒做上帝知道什么,在deplyoing之前     并启动自上次构建以来未更改的应用程序?

前8秒似乎用于构建构建脚本(“配置”)

接下来的9秒用于执行以下任务:

: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

发生什么事了?为什么我作为开发人员需要花17秒等待构建系统确定没有任何变化?

有没有可以解决这个缺点的黑客,所以当我只是想从Android Studio重新启动我的应用程序时,我不需要等待它重新编译?

我知道我可以创建一个Run配置,我删除了“Make”步骤,  但接着确定是否有任何改变的过程,  由我作为开发人员来决定。我认为这不是一个可以接受的解决方案。

1 个答案:

答案 0 :(得分:4)

使用gradle daemon,使用gradle.properties对其进行配置。

  

Gradle守护程序(有时称为构建守护程序)旨在改善Gradle的启动和执行时间

Gradle是基于java的工具。 大部分时间都花在启动JVM上。你的8秒和9秒是由Java编译和JVM启动引起的。 Gradle守护程序将抵消这些问题。

TL; DR; Gradle守护进程将使您的构建更快。

将gradle.properties文件添加到build.gradle所在的文件夹中。添加以下属性此文件。

org.gradle.daemon=true

查看两次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

由于gradle守护程序,第二个快得多。