【问题标题】:Why does Android Studio / Gradle rebuild my application when no changes have been made?为什么没有进行任何更改时,Android Studio / Gradle 会重建我的应用程序?
【发布时间】:2015-01-04 05:13:01
【问题描述】:

在“过去”中,构建工具知道什么时候可以通过以下方式重新构建应用程序,而不必重新构建应用程序 查看各个源文件的时间戳。为什么 Gradle,最现代的工具 对于构建 Android 应用程序,在我的情况下使用 17 秒来做上帝知道什么,然后再部署 并启动自上次构建以来未更改的应用程序?

前 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 重新启动我的应用时,我不需要等待它重新编译?

我知道我可以创建一个运行配置,在其中删除“制作”步骤, 然后是确定是否有任何改变的过程, 由我作为开发人员来决定。我不认为这是一个可以接受的解决方案。

【问题讨论】:

  • 我也觉得这很令人沮丧。我已经开始赏金,希望有人能提供解决方案。
  • this Stack Overflow question的回复有帮助吗?
  • 插件和 gradle 的更高版本以及您的线程 Joel 中建议的配置肯定有帮助。不过,要达到 Eclipse 或 Idea/Maven 标准还有很长的路要走。我仍然不明白为什么在没有进行任何更改的情况下必须进行任何编译/索引。

标签: intellij-idea gradle android-studio


【解决方案1】:

使用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 守护进程,第二个要快得多。

【讨论】:

  • 请提供一个示例grade.properties,而不是仅仅链接到文档。是的,我有点赶时间深入学习这个。
  • @SSR 添加了示例 gradle.properties 文件
  • 这解决了一半的问题,感谢您的意见。剩下的一半仍然是 gradle(或 android-gradle 插件)花费太多时间确定项目不变的问题。您的示例不执行任何任务,因此它在 3.578 秒内完成。当您执行任务“assembleDebug”(第二次运行)时,情况不会接近
猜你喜欢
  • 1970-01-01
  • 2021-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-11
  • 1970-01-01
相关资源
最近更新 更多