refactor(build): Introduce AndroidLibraryFlavors convention plugin (#4449)

This commit is contained in:
James Rich 2026-02-04 16:01:09 -06:00 committed by GitHub
parent 854eff685e
commit 3eefa801d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 60 additions and 79 deletions

View file

@ -112,7 +112,7 @@ gradlePlugin {
id = "meshtastic.android.application"
implementationClass = "AndroidApplicationConventionPlugin"
}
register("androidFlavors") {
register("androidApplicationFlavors") {
id = "meshtastic.android.application.flavors"
implementationClass = "AndroidApplicationFlavorsConventionPlugin"
}
@ -120,6 +120,10 @@ gradlePlugin {
id = "meshtastic.android.library"
implementationClass = "AndroidLibraryConventionPlugin"
}
register("androidLibraryFlavors") {
id = "meshtastic.android.library.flavors"
implementationClass = "AndroidLibraryFlavorsConventionPlugin"
}
register("androidLint") {
id = "meshtastic.android.lint"
implementationClass = "AndroidLintConventionPlugin"
@ -167,12 +171,12 @@ gradlePlugin {
id = "meshtastic.kmp.library.compose"
implementationClass = "KmpLibraryComposeConventionPlugin"
}
register("dokka") {
id = "meshtastic.dokka"
implementationClass = "DokkaConventionPlugin"
}
register("kover") {
id = "meshtastic.kover"
implementationClass = "KoverConventionPlugin"

View file

@ -21,7 +21,6 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.meshtastic.buildlogic.configureFlavors
import org.meshtastic.buildlogic.configureKotlinAndroid
import org.meshtastic.buildlogic.configureTestOptions
import org.meshtastic.buildlogic.disableUnnecessaryAndroidTests
@ -41,7 +40,12 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
configureKotlinAndroid(this)
defaultConfig.testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testOptions.animationsDisabled = true
configureFlavors(this)
defaultConfig {
// When flavorless modules depend on flavored modules (like :core:data),
// they need a strategy to pick a variant. We default to 'google'.
missingDimensionStrategy("marketplace", "google")
}
buildTypes {
getByName("debug") {

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import com.android.build.api.dsl.LibraryExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.meshtastic.buildlogic.configureFlavors
class AndroidLibraryFlavorsConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
extensions.configure<LibraryExtension> {
configureFlavors(this)
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2025 Meshtastic LLC
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,24 +16,9 @@
*/
import com.android.build.api.dsl.LibraryExtension
/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
plugins {
alias(libs.plugins.meshtastic.android.library)
alias(libs.plugins.meshtastic.android.library.flavors)
alias(libs.plugins.meshtastic.android.library.compose)
alias(libs.plugins.meshtastic.hilt)
alias(libs.plugins.secrets)

View file

@ -30,15 +30,15 @@ configure<com.android.build.api.dsl.LibraryExtension> {
minSdk = 21
}
publishing { singleVariant("googleRelease") { withSourcesJar() } }
publishing { singleVariant("release") { withSourcesJar() } }
}
// Map the Android component to a Maven publication
afterEvaluate {
publishing {
publications {
create<MavenPublication>("googleRelease") {
from(components["googleRelease"])
create<MavenPublication>("release") {
from(components["release"])
artifactId = "core-api"
}
}

View file

@ -18,6 +18,7 @@ import com.android.build.api.dsl.LibraryExtension
plugins {
alias(libs.plugins.meshtastic.android.library)
alias(libs.plugins.meshtastic.android.library.flavors)
alias(libs.plugins.meshtastic.hilt)
alias(libs.plugins.meshtastic.kotlinx.serialization)
}

View file

@ -39,14 +39,14 @@ configure<LibraryExtension> {
testOptions { unitTests { isIncludeAndroidResources = true } }
publishing { singleVariant("googleRelease") { withSourcesJar() } }
publishing { singleVariant("release") { withSourcesJar() } }
}
afterEvaluate {
publishing {
publications {
create<MavenPublication>("googleRelease") {
from(components["googleRelease"])
create<MavenPublication>("release") {
from(components["release"])
artifactId = "core-model"
}
}

View file

@ -16,25 +16,9 @@
*/
import com.android.build.api.dsl.LibraryExtension
/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
plugins {
alias(libs.plugins.meshtastic.android.library)
alias(libs.plugins.meshtastic.android.library.flavors)
alias(libs.plugins.meshtastic.hilt)
alias(libs.plugins.kotlin.serialization)
}

View file

@ -16,25 +16,9 @@
*/
import com.android.build.api.dsl.LibraryExtension
/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
plugins {
alias(libs.plugins.meshtastic.android.library)
alias(libs.plugins.meshtastic.android.library.flavors)
alias(libs.plugins.meshtastic.hilt)
}

View file

@ -16,25 +16,9 @@
*/
import com.android.build.api.dsl.LibraryExtension
/*
* Copyright (c) 2025 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
plugins {
alias(libs.plugins.meshtastic.android.library)
alias(libs.plugins.meshtastic.android.library.flavors)
alias(libs.plugins.meshtastic.android.library.compose)
alias(libs.plugins.meshtastic.kotlinx.serialization)
}

View file

@ -18,6 +18,7 @@ import com.android.build.api.dsl.LibraryExtension
plugins {
alias(libs.plugins.meshtastic.android.library)
alias(libs.plugins.meshtastic.android.library.flavors)
alias(libs.plugins.meshtastic.android.library.compose)
alias(libs.plugins.meshtastic.hilt)
}

View file

@ -18,6 +18,7 @@ import com.android.build.api.dsl.LibraryExtension
plugins {
alias(libs.plugins.meshtastic.android.library)
alias(libs.plugins.meshtastic.android.library.flavors)
alias(libs.plugins.meshtastic.android.library.compose)
alias(libs.plugins.meshtastic.hilt)
}

View file

@ -246,6 +246,7 @@ meshtastic-android-application-compose = { id = "meshtastic.android.application.
meshtastic-android-application-flavors = { id = "meshtastic.android.application.flavors" }
meshtastic-android-library = { id = "meshtastic.android.library" }
meshtastic-android-library-compose = { id = "meshtastic.android.library.compose" }
meshtastic-android-library-flavors = { id = "meshtastic.android.library.flavors" }
meshtastic-android-lint = { id = "meshtastic.android.lint" }
meshtastic-android-room = { id = "meshtastic.android.room" }
meshtastic-android-test = { id = "meshtastic.android.test" }