intellij-idea - 为什么 Android Studio/Gradle 在没有进行任何更改的情况下重建我的应用程序?

标签 intellij-idea gradle android-studio

在“旧时代”,构建工具知道什么时候需要重新构建应用程序
查看各个源文件的时间戳。为什么 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 重新启动我的应用程序时,我不需要等待它重新编译?

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

最佳答案

使用 gradle daemon , 使用 gradle.properties 配置它.

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



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

TL; 博士;
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 守护进程,第二个要快得多。

关于intellij-idea - 为什么 Android Studio/Gradle 在没有进行任何更改的情况下重建我的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26800779/

相关文章:

Android Studio 2.2 找不到所有 kotlin 文件的引用

android - Gradle同步在Android Studio 1.4.1中失败

android - 当我在滚动 Android Studio 后动态更新时,ListView 不会保留状态

android - 从 android arsenal 添加存储库的问题

java - Intellij 无法识别 pom.xml 中的环境变量

intellij-idea - Intellij 14 奇怪的编辑器/光标行为

intellij-idea - IntelliJ IDEA 的 Gradle 语言级别是如何确定的?

android - 错误:Execution failed for task ':app:transformClassesWithDexForDebug' .没有解决

java - IntelliJ 中的属性文件问题(添加到类路径)JSP(空指针 ex)

git - Windows 10 上 Intellij 的 GIT 终端中的自动完成分支名称