Skip to content

Commit

Permalink
AGP 8.2 and 8.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner committed Nov 28, 2023
1 parent 2ab6a88 commit e230484
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.freeletics.gradle.monorepo.plugin

import com.android.build.api.AndroidPluginVersion
import com.freeletics.gradle.monorepo.setup.applyPlatformConstraints
import com.freeletics.gradle.monorepo.setup.disableAndroidApplicationTasks
import com.freeletics.gradle.monorepo.tasks.CheckDependencyRulesTask.Companion.registerCheckDependencyRulesTasks
Expand All @@ -8,6 +9,7 @@ import com.freeletics.gradle.monorepo.util.appType
import com.freeletics.gradle.plugin.FreeleticsAndroidAppPlugin
import com.freeletics.gradle.util.androidApp
import com.freeletics.gradle.util.androidComponents
import com.freeletics.gradle.util.androidPluginVersion
import com.freeletics.gradle.util.freeleticsAndroidExtension
import com.freeletics.gradle.util.freeleticsExtension
import com.freeletics.gradle.util.stringProperty
Expand Down Expand Up @@ -50,6 +52,11 @@ public abstract class AppPlugin : Plugin<Project> {
}
}

androidResources {
@Suppress("UnstableApiUsage")
generateLocaleConfig = target.androidPluginVersion >= AndroidPluginVersion(8, 2, 0).rc(1)
}

buildTypes {
named("debug") {
it.applicationIdSuffix = ".debug"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.freeletics.gradle.monorepo.setup

import com.android.build.api.AndroidPluginVersion
import com.android.build.api.variant.AndroidComponentsExtension
import com.freeletics.gradle.monorepo.util.capitalize
import com.freeletics.gradle.util.androidPluginVersion
import org.gradle.api.Project

internal fun Project.disableAndroidApplicationTasks() {
Expand Down Expand Up @@ -31,6 +33,11 @@ private fun Project.disableAndroidTasks(names: List<String>, variantToKeep: Stri
}

private fun Project.disableTasks(names: List<String>) {
// since AGP 8.3 the tasks.named will fail during project sync
if (providers.systemProperty("idea.sync.active").getOrElse("false").toBoolean()) {
return
}

afterEvaluate {
names.forEach { name ->
tasks.named(name).configure {
Expand All @@ -53,12 +60,16 @@ private val androidLibraryTasksToDisable = listOf(
// for libraries remove all reporting tasks so that they only
// have the analyze task since we have an aggregated report at
// the app level
private val androidLibraryLintTasksToDisable = listOf(
private val Project.androidLibraryLintTasksToDisable get() = listOf(
// report
"lint",
"lint{VARIANT}",
"lintReport{VARIANT}",
"copy{VARIANT}AndroidLintReports",
if (androidPluginVersion >= AndroidPluginVersion(8, 2, 0).rc(1)) {
"copy{VARIANT}LintReports"
} else {
"copy{VARIANT}AndroidLintReports"
},
// fix
"lintFix",
"lintFix{VARIANT}",
Expand All @@ -74,13 +85,17 @@ private val androidLibraryLintTasksToDisableExceptOneVariant = listOf(
)

// disable debug variant of these tasks, we're only running on release
private val androidAppLintTasksToDisableExceptOneVariant = listOf(
private val Project.androidAppLintTasksToDisableExceptOneVariant get() = listOf(
// analyze
"lintAnalyze{VARIANT}",
// report
"lint{VARIANT}",
"lintReport{VARIANT}",
"copy{VARIANT}AndroidLintReports",
if (androidPluginVersion >= AndroidPluginVersion(8, 2, 0).rc(1)) {
"copy{VARIANT}LintReports"
} else {
"copy{VARIANT}AndroidLintReports"
},
// fix
"lintFix{VARIANT}",
// baseline
Expand All @@ -89,14 +104,35 @@ private val androidAppLintTasksToDisableExceptOneVariant = listOf(

// same as the Android library tasks, only keep analyze and the report
// is created in the app module
private val lintTasksToDisableJvm = listOf(
"lint",
"lintReport",
"copyAndroidLintReports",
"lintFix",
"updateLintBaseline",
// TODO these shouldn't be created by AGP in the first place
"lintVital",
"lintVitalAnalyze",
"lintVitalReport",
)
private val Project.lintTasksToDisableJvm
get() = if (androidPluginVersion >= AndroidPluginVersion(8, 2, 0).rc(1)) {
listOf(
"lint",
"lintJvm",
"lintReportJvm",
"copyJvmLintReports",
"lintFix",
"lintFixJvm",
"updateLintBaseline",
"updateLintBaselineJvm",
"lintVital",
"lintVitalJvm",
if (androidPluginVersion >= AndroidPluginVersion(8, 3, 0).alpha(14)) {
"lintVitalAnalyzeJvm"
} else {
"lintVitalAnalyzeJvmMain"
},
"lintVitalReportJvm",
)
} else {
listOf(
"lint",
"lintReport",
"copyAndroidLintReports",
"lintFix",
"updateLintBaseline",
"lintVital",
"lintVitalAnalyze",
"lintVitalReport",
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.freeletics.gradle.util

import com.android.build.api.AndroidPluginVersion
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.dsl.CommonExtension
import com.android.build.api.dsl.LibraryExtension
Expand Down Expand Up @@ -61,6 +62,9 @@ internal fun Project.androidApp(action: ApplicationExtension.() -> Unit) {
}
}

internal val Project.androidPluginVersion: AndroidPluginVersion
get() = extensions.getByType(AndroidComponentsExtension::class.java).pluginVersion

internal fun Project.androidComponents(action: AndroidComponentsExtension<*, *, *>.() -> Unit) {
extensions.configure(AndroidComponentsExtension::class.java) {
it.action()
Expand Down

0 comments on commit e230484

Please sign in to comment.