Skip to content

Commit

Permalink
Migrate to faster build configuration (#311)
Browse files Browse the repository at this point in the history
**Background**
Make faster builds.

**Changes**
1. Increase -Xms from 2g to 3g
5.2% (8.8s) of  build’s time was wasted to garbage collection. 
2. Replace all to bin gradle distribution. 
Just smaller jar, no docs, no sources.
3. Disable unnecessary android buildFeatures.
Less tasks = faster build
4. Disable viewBinding by default.
ViewBinding needed only for few modules. No need to enable this feature for all modules.
5. Disable Jetifier.
All project modules do not use any legacy support libs. (see [checkJetifierReport.txt](https://github.com/flipperdevices/Flipper-Android-App/files/9364391/checkJetifierReport.txt))

Should be faster more than 15%

**Test plan**
Green pipelines.
  • Loading branch information
rougsig authored Aug 17, 2022
1 parent d71c387 commit 4761348
Show file tree
Hide file tree
Showing 97 changed files with 365 additions and 242 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [REFACTOR] Redesign Full Device Information
- [REFACTOR] Redesign dialog after update (change colors)
- [REFACTOR] Migrate to faster build configuration

# 1.2.0

Expand Down
2 changes: 1 addition & 1 deletion buildSrc/.gitignore → build-logic/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.gradle/
/build
build
13 changes: 13 additions & 0 deletions build-logic/plugins/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
`kotlin-dsl`
}

dependencies {
implementation(libs.android.gradle)
implementation(libs.detekt.gradle)
implementation(libs.kotlin.gradle)
implementation(libs.ktlint.gradle)
implementation(libs.sentry.gradle)

implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.flipperdevices.buildlogic

import java.lang.System.getProperty

object ApkConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.kotlin.dsl.add
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.flipperdevices.buildlogic.ApkConfig

private const val SPLASH_SCREEN_ACTIVITY = "com.flipperdevices.app.SplashScreen"
private const val SPLASH_SCREEN_ACTIVITY_KEY = "splashScreenActivity"
Expand Down Expand Up @@ -91,7 +92,18 @@ private fun BaseExtension.configureBuildTypes() {

@Suppress("UnstableApiUsage")
private fun BaseExtension.configureBuildFeatures() {
buildFeatures.viewBinding = true
// TODO: Disable by default
// BuildConfig is java source code. Java and Kotlin at one time affect build speed.
buildFeatures.buildConfig = true
// Disable by default. ViewBinding needed only for few modules.
// No need to enable this feature for all modules.
buildFeatures.viewBinding = false
buildFeatures.aidl = false
buildFeatures.compose = false
buildFeatures.prefab = false
buildFeatures.renderScript = false
buildFeatures.resValues = false
buildFeatures.shaders = false
}

private fun BaseExtension.configureCompileOptions() {
Expand Down Expand Up @@ -131,8 +143,20 @@ private fun Project.suppressOptIn() {
fun DependencyHandler.internalImplementation(dependencyNotation: Any): Dependency? =
add("internalImplementation", dependencyNotation)

fun <BuildTypeT> NamedDomainObjectContainer<BuildTypeT>.debug(
action: BuildTypeT.() -> Unit
) {
maybeCreate("debug").action()
}

fun <BuildTypeT> NamedDomainObjectContainer<BuildTypeT>.internal(
action: BuildTypeT.() -> Unit
) {
maybeCreate("internal").action()
}

fun <BuildTypeT> NamedDomainObjectContainer<BuildTypeT>.release(
action: BuildTypeT.() -> Unit
) {
maybeCreate("release").action()
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import com.android.build.gradle.BaseExtension
import com.flipperdevices.buildlogic.ApkConfig
import io.sentry.android.gradle.extensions.SentryPluginExtension

plugins {
id("com.android.application")
id("kotlin-android")
id("io.sentry.android.gradle")
}

@Suppress("UnstableApiUsage")
android {
configure<BaseExtension> {
commonAndroid(project)

defaultConfig {
Expand All @@ -25,7 +29,7 @@ android {
}
}

sentry {
configure<SentryPluginExtension> {
autoUploadProguardMapping.set(ApkConfig.IS_SENTRY_PUBLISH)

ignoredBuildTypes.set(setOf("release", "debug"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import com.android.build.gradle.BaseExtension

plugins {
id("flipper.android-lib")
}

@Suppress("UnstableApiUsage")
configure<BaseExtension> {
buildFeatures.compose = true

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import com.android.build.gradle.BaseExtension

plugins {
id("com.android.library")
id("kotlin-android")
kotlin("kapt")
}

android {
configure<BaseExtension> {
commonAndroid(project)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import com.flipperdevices.buildlogic.ApkConfig

tasks.register("dumpApkVersion") {
val CODE_PROP = "version_code"
val NAME_PROP = "version_name"

val outputFileProvider = layout.buildDirectory.file("version/apk-version.properties")

inputs.property(CODE_PROP, provider { ApkConfig.VERSION_CODE })
inputs.property(NAME_PROP, provider { ApkConfig.VERSION_NAME })
outputs.file(outputFileProvider)

doLast {
val outputFile = outputFileProvider.get().asFile
outputFile.deleteOnExit()
outputFile.parentFile.mkdirs()

val props = java.util.Properties()
props.setProperty(CODE_PROP, inputs.properties[CODE_PROP].toString())
props.setProperty(NAME_PROP, inputs.properties[NAME_PROP].toString())
props.store(outputFile.writer(), /* comments = */ null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import org.gradle.kotlin.dsl.configure
import org.jlleitschuh.gradle.ktlint.KtlintExtension
import io.gitlab.arturbosch.detekt.extensions.DetektExtension

plugins {
id("io.gitlab.arturbosch.detekt")
id("org.jlleitschuh.gradle.ktlint")
}

configure<KtlintExtension> {
version.set(libs.versions.ktlint.runtime)
android.set(true)
verbose.set(true)
outputToConsole.set(true)
ignoreFailures.set(false)
enableExperimentalRules.set(true)
filter {
exclude("**/generated/**")
include("**/kotlin/**")
}
}

configure<DetektExtension> {
config = rootProject.files("config/detekt/detekt.yml")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.Project
import org.gradle.kotlin.dsl.the

// Workaround for https://github.com/gradle/gradle/issues/15383
val Project.libs: LibrariesForLibs
get() = the<LibrariesForLibs>()
25 changes: 25 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pluginManagement {
repositories {
google()
gradlePluginPortal()
}
}

dependencyResolutionManagement {
repositories {
google()
gradlePluginPortal()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"

include(
":plugins:convention",
)
68 changes: 11 additions & 57 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,59 +1,13 @@
plugins {
id("com.android.application") apply false
id("com.android.library") apply false
kotlin("android") apply false
alias(libs.plugins.detekt)
alias(libs.plugins.ktlint)
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}

val ktLintVersion: String = libs.versions.ktlint.runtime.get()

subprojects {
apply {
plugin("io.gitlab.arturbosch.detekt")
plugin("org.jlleitschuh.gradle.ktlint")
}

ktlint {
version.set(ktLintVersion)
android.set(true)
verbose.set(true)
outputToConsole.set(true)
ignoreFailures.set(false)
enableExperimentalRules.set(true)
filter {
exclude("**/generated/**")
include("**/kotlin/**")
}
}

detekt {
config = rootProject.files("config/detekt/detekt.yml")
}
}

tasks.register("dumpApkVersion") {
val CODE_PROP = "version_code"
val NAME_PROP = "version_name"

val outputFileProvider = layout.buildDirectory.file("version/apk-version.properties")

inputs.property(CODE_PROP, provider { ApkConfig.VERSION_CODE })
inputs.property(NAME_PROP, provider { ApkConfig.VERSION_NAME })
outputs.file(outputFileProvider)

doLast {
val outputFile = outputFileProvider.get().asFile
outputFile.deleteOnExit()
outputFile.parentFile.mkdirs()

val props = java.util.Properties()
props.setProperty(CODE_PROP, inputs.properties[CODE_PROP].toString())
props.setProperty(NAME_PROP, inputs.properties[NAME_PROP].toString())
props.store(outputFile.writer(), /* comments = */ null)
}
alias(libs.plugins.android.app) apply false
alias(libs.plugins.android.lib) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.kotlin.ksp) apply false
alias(libs.plugins.square.anvil) apply false
alias(libs.plugins.protobuf) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.ktlint) apply false

id("flipper.fdroid")
}
38 changes: 0 additions & 38 deletions buildSrc/build.gradle.kts

This file was deleted.

12 changes: 0 additions & 12 deletions buildSrc/settings.gradle.kts

This file was deleted.

14 changes: 0 additions & 14 deletions buildSrc/src/main/java/androidCompose.gradle.kts

This file was deleted.

10 changes: 0 additions & 10 deletions buildSrc/src/main/java/versionCatalog.kt

This file was deleted.

3 changes: 2 additions & 1 deletion components/analytics/metric/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
androidLibrary
id("flipper.lint")
id("flipper.android-lib")
}

dependencies {
Expand Down
5 changes: 4 additions & 1 deletion components/analytics/metric/impl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import com.flipperdevices.buildlogic.ApkConfig

plugins {
androidLibrary
id("flipper.lint")
id("flipper.android-lib")
id("com.squareup.anvil")
id("kotlin-kapt")
}
Expand Down
3 changes: 2 additions & 1 deletion components/analytics/shake2report/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
androidLibrary
id("flipper.lint")
id("flipper.android-lib")
}

dependencies {
Expand Down
Loading

0 comments on commit 4761348

Please sign in to comment.