El *_*uli 13 android gradle android-studio
MBP 2015,8GB RAM,SSD
Android Studio 2.2.3
---自定义VM选项:
-Xms1024m
-Xmx8192m
-XX:MaxPermSize=1024m
-XX:ReservedCodeCacheSize=440m
-XX:+UseCompressedOops
-XX:+HeapDumpOnOutOfMemoryError
-Dfile.encoding=UTF-8
Run Code Online (Sandbox Code Playgroud)
---按需编译/配置
---并行编译/编译模块
--- Gradle /离线工作
--- gradle.properties文件:
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx8192m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -noverify
org.gradle.parallel=true
org.gradle.configureondemand=true
android.enableBuildCache=true
Run Code Online (Sandbox Code Playgroud)
有没有人知道发生了什么,因为它只是荒谬
从那以后我切换到一个16GB的内存,显然有一些改进,我的印象是它不到一分钟左右,但需要3-4分钟,这仍然是不可接受的:这里是Gradle的一部分我发现的日志耗时太长:
git log --pretty=format:'%h %s'
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preAlphaBuild UP-TO-DATE
:app:preBirdsBuild UP-TO-DATE
:app:preKfgBuild UP-TO-DATE
:app:prePenBuild UP-TO-DATE
:app:prePrelaunchBuild UP-TO-DATE
:app:prePtr1Build UP-TO-DATE
:app:prePtr3Build UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:prepareCnPedantSweetalertLibrary13Library
:app:prepareComAndroidSupportAnimatedVectorDrawable2511Library
:app:prepareComAndroidSupportAppcompatV72511Library
:app:prepareComAndroidSupportCardviewV72511Library
:app:prepareComAndroidSupportDesign2511Library
:app:prepareComAndroidSupportMultidex101Library
:app:prepareComAndroidSupportRecyclerviewV72511Library
:app:prepareComAndroidSupportSupportCompat2511Library
:app:prepareComAndroidSupportSupportCoreUi2511Library
:app:prepareComAndroidSupportSupportCoreUtils2511Library
:app:prepareComAndroidSupportSupportFragment2511Library
:app:prepareComAndroidSupportSupportMediaCompat2511Library
:app:prepareComAndroidSupportSupportV132511Library
:app:prepareComAndroidSupportSupportV42511Library
:app:prepareComAndroidSupportSupportVectorDrawable2511Library
:app:prepareComAndroidSupportTransition2511Library
:app:prepareComCrashlyticsSdkAndroidAnswers1310Library
:app:prepareComCrashlyticsSdkAndroidBeta122Library
:app:prepareComCrashlyticsSdkAndroidCrashlytics265Library
:app:prepareComCrashlyticsSdkAndroidCrashlyticsCore2314Library
:app:prepareComDevbracketsAndroidExomedia311Library
:app:prepareComEftimoffAndroidViewpagerTransformers101Library
:app:prepareComGithubCastorflexSmoothprogressbarLibrary110Library
:app:prepareComGithubHotchemiPermissionsdispatcher230Library
:app:prepareComGithubKibotuAndroidAnimationsActions107Library
:app:prepareComGithubKibotuBloodHound105Library
:app:prepareComGithubKibotuCommonAndroidUtils072Library
:app:prepareComGithubKibotuGooglePlayForceUpdate108Library
:app:prepareComGithubKibotuNetKibotuAndroidDeviceinfo121Library
:app:prepareComGithubKibotuOpenAndroidSSLWrapper107Library
:app:prepareComGithubKibotuRecyclerViewPresenter141Library
:app:prepareComGithubKibotuShareIntentBuilderV003Library
:app:prepareComGithubKibotuTimeBomb110Library
:app:prepareComGithubKibotuUrlShortener107Library
:app:prepareComGithubOrhanobutHawk123Library
:app:prepareComGithubOzodrukhCircularReveal201Library
:app:prepareComGoogleAndroidExoplayerExoplayerR1513Library
:app:prepareComGoogleAndroidGmsPlayServicesAds1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAdsLite1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics1001Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl1001Library
:app:prepareComGoogleAndroidGmsPlayServicesBase1001Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement1001Library
:app:prepareComGoogleAndroidGmsPlayServicesClearcut1001Library
:app:prepareComGoogleAndroidGmsPlayServicesGass1001Library
:app:prepareComGoogleAndroidGmsPlayServicesGcm1001Library
:app:prepareComGoogleAndroidGmsPlayServicesIid1001Library
:app:prepareComGoogleAndroidGmsPlayServicesLocation1001Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanagerV4Impl1001Library
:app:prepareComGoogleAndroidGmsPlayServicesTasks1001Library
:app:prepareComGoogleFirebaseFirebaseAnalytics1001Library
:app:prepareComGoogleFirebaseFirebaseAnalyticsImpl1001Library
:app:prepareComGoogleFirebaseFirebaseCommon1001Library
:app:prepareComGoogleFirebaseFirebaseCore1001Library
:app:prepareComGoogleFirebaseFirebaseIid1001Library
:app:prepareComGoogleFirebaseFirebaseMessaging1001Library
:app:prepareComJakewhartonButterknife840Library
:app:prepareComJakewhartonProcessPhoenix110Library
:app:prepareComMikepenzFastadapter210Library
:app:prepareComMikepenzIconicsCore280Library
:app:prepareComMikepenzMaterialdrawer581Library
:app:prepareComMikepenzMaterialize100Library
:app:prepareComMukeshMarkdownview100Library
:app:prepareComNightonkeJellytogglebutton102Library
:app:prepareComNightonkeWowoviewpager102Library
:app:prepareComOgaclejapanSmarttablayoutLibrary161Library
:app:prepareComOgaclejapanSmarttablayoutUtilsV4161Library
:app:prepareComPnikosisMaterialishProgress10Library
:app:prepareComSbrukhandaFragmentviewpagerFragmentviewpager100Library
:app:prepareComShawnlinNumberPicker101Library
:app:prepareComSloydevPreferator100Library
:app:prepareComYydcdutRxmarkdown005Library
:app:prepareComZplesacConnectionbuddy140Library
:app:prepareHanksXyzHtextviewLibrary015Library
:app:prepareIoFabricSdkAndroidFabric1314Library
:app:prepareIoNlopezSmartlocationLibrary329Library
:app:prepareIoReactivexRxandroid121Library
:app:prepareJpWasabeefGlideTransformations201Library
:app:prepareJpWasabeefRecyclerviewAnimators225Library
:app:prepareMeGrantlandAutofittextview021Library
:app:prepareMeRelexCircleindicator122Library
:app:prepareNetDanlewAndroidJoda297Library
:app:prepareUkCoChrisjenxCalligraphy220Library
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig
:app:mergeDebugShaders UP-TO-DATE
:app:compileDebugShaders UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:fabricGenerateResourcesDebug
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
Parsing json file: ../google-services.json
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugResources
:app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard
:app:javaPreCompileDebug
:app:compileDebugKotlin
Run Code Online (Sandbox Code Playgroud)
直到这里很好,但:app:compileDebugKotlin需要大约60秒以上......
然后,
...
...
:app:copyDebugKotlinClasses
:app:compileDebugNdk NO-SOURCE
:app:compileDebugSources
:app:transformClassesWithRetrolambdaForDebug
:app:transformClassesWithDexForDebug
Run Code Online (Sandbox Code Playgroud)
这最后一行也能保持这么长时间.
Ali*_*adi 16
对于kotlin用户增量构建
编译器最重要的性能特征之一是使用渐进式编译.正常构建将重新编译项目中的所有源文件,但增量构建将跟踪自上次构建以来哪些文件已更改,并且仅重新编译这些文件以及依赖于它们的文件.这会对编译时间产生巨大影响,尤其是对于大型项目.
增量版本已添加到版本1.0.2中的Kotlin,您可以通过向gradle.properties添加kotlin.incremental = true来启用它们.
更多细节:https://medium.com/keepsafe-engineering/kotlin-vs-java-compilation-speed-e6c174b39b5d
将这行代码添加到gradle.properties也很有用
// Add this in your global gradle.properties file
// at ~/.gradle/gradle.properties
// Enable Gradle Daemon
org.gradle.daemon=true
// Enable Configure on demand
org.gradle.configureondemand=true
//Enable parallel builds
org.gradle.parallel=true
// Enable Build Cache
android.enableBuildCache=true
//Enable simple gradle caching
org.gradle.caching=true
// Increase memory allotted to JVM
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -
XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Run Code Online (Sandbox Code Playgroud)
如果从repo中心下载所有依赖项,则可以使gradle脱机表单
File->Setting->Build, Execution, Deploymennt->Gradle
小智 7
File->Setting->Build, Execution, Deploymennt->Gradle
Check Offline work
Click Apply and Ok
Run Code Online (Sandbox Code Playgroud)
您需要发布更多信息以便我们提供帮助。
发布您的 build.gradle 文件以及您的应用程序有多少个模块以及 gradle.properties 文件和 settings.gradle 文件。
您还可以查看 Mac 上的 Activiy Monitor,看看在后台运行的其他内容可能会占用一些资源。
8 GB 的 RAM 并不多,因此您应该尝试关闭可能占用部分 RAM 的其他元素。
在应用程序的 build.gradle 文件中的“android”块中试试这个:
dexOptions {
preDexLibraries true
javaMaxHeapSize "4G"
}
Run Code Online (Sandbox Code Playgroud)
与此一起在您的 gradle.properties 文件中:
org.gradle.jvmargs=-Xmx4608M
Run Code Online (Sandbox Code Playgroud)
由于您“只有” 8 GB 的 RAM,您不应该像之前尝试的那样尝试将 8 GB 专用于 Gradle。
我有 16 GB 的 RAM,我为 Gradle 使用了 4-5 GB,并且构建速度非常快。即使是我们最大的项目,在 7 年后仍在开发中,从头开始构建也需要 2-3 分钟。
但是,请发布我在本文开头要求的信息,我们可以提供更多帮助。
如果您有很大的代码库,那么需要时间是很正常的。或者更好的是,预计需要一些时间。我刚刚注意到您在项目中使用了 Kotlin,这意味着您的 java 代码编译有 2 个阶段,而不是只有 1 个阶段。
Kotlin 在第一阶段被编译(和 java 引用)。之后,您将进行第二阶段的编译,即编译纯 Java。这意味着平均编译时间要长两倍。
编译: Java 代码 + Kotlin -> Kotlin 编译器 Java 代码 + 解析的 Kotlin 代码 -> Java 编译器 deshing 以及其他所有内容
我的建议是,将代码拆分为模块。如果您可以按语言分隔模块就更好了。这样 Kotlin 模块会很慢,但 java 模块会更快。
如果您有完全独立的 Java 和 Kotlin 模块,那么它所花费的时间应该与 Java 大致相同。
结论:
模块化您的代码将加快构建速度。如果你想要 Kotlin,减少 Java 代码,它会加快构建速度。将 Kotlin 和 Java 模块分开,需要更少的编译,某些模块的阶段也更少,因此会加快构建速度。
| 归档时间: |
|
| 查看次数: |
13459 次 |
| 最近记录: |