refactor(build): Create a dedicated analytics convention plugin (#3961)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich
2025-12-10 22:47:25 -06:00
committed by GitHub
parent ce732203ae
commit fdff7315fe
6 changed files with 78 additions and 20 deletions

View File

@@ -140,13 +140,6 @@ android {
// Configure existing product flavors (defined by convention plugin)
// with their dynamic version names.
productFlavors {
all {
if (name == "google") {
apply(plugin = libs.plugins.google.services.get().pluginId)
apply(plugin = libs.plugins.firebase.crashlytics.get().pluginId)
}
}
named("google") { versionName = "${defaultConfig.versionName} (${defaultConfig.versionCode}) google" }
named("fdroid") { versionName = "${defaultConfig.versionName} (${defaultConfig.versionCode}) fdroid" }
}

View File

@@ -131,6 +131,10 @@ gradlePlugin {
id = libs.plugins.meshtastic.kotlinx.serialization.get().pluginId
implementationClass = "KotlinXSerializationConventionPlugin"
}
register("meshtasticAnalytics") {
id = libs.plugins.meshtastic.analytics.get().pluginId
implementationClass = "AnalyticsConventionPlugin"
}
register("meshtasticHilt") {
id = libs.plugins.meshtastic.hilt.get().pluginId
implementationClass = "HiltConventionPlugin"

View File

@@ -0,0 +1,61 @@
/*
* 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.ApplicationExtension
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.datadog.gradle.plugin.DdExtension
import com.datadog.gradle.plugin.InstrumentationMode
import com.datadog.gradle.plugin.SdkCheckLevel
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
class AnalyticsConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
extensions.configure<ApplicationExtension> {
defaultConfig {
productFlavors {
all {
if (name == "google") {
apply(plugin = "com.google.gms.google-services")
apply(plugin = "com.google.firebase.crashlytics")
apply(plugin = "com.datadoghq.dd-sdk-android-gradle-plugin")
}
}
}
}
}
extensions.configure<ApplicationAndroidComponentsExtension> {
onVariants { variant ->
if (variant.flavorName == "google") {
extensions.configure<DdExtension> {
variants {
register(variant.name) {
site = "US5"
composeInstrumentation = InstrumentationMode.AUTO
}
}
checkProjectDependencies = SdkCheckLevel.NONE
}
}
}
}
}
}
}

View File

@@ -17,12 +17,10 @@
import com.android.build.api.dsl.ApplicationExtension
import com.geeksville.mesh.buildlogic.configureKotlinAndroid
import com.geeksville.mesh.buildlogic.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
class AndroidApplicationConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
@@ -33,6 +31,7 @@ class AndroidApplicationConventionPlugin : Plugin<Project> {
apply(plugin = "meshtastic.android.lint")
apply(plugin = "meshtastic.detekt")
apply(plugin = "meshtastic.spotless")
apply(plugin = "meshtastic.analytics")
apply(plugin = "com.autonomousapps.dependency-analysis")
extensions.configure<ApplicationExtension> {

View File

@@ -30,17 +30,17 @@ dependencies {
implementation(libs.androidx.navigation.runtime)
implementation(libs.timber)
googleImplementation(libs.dd.sdk.android.compose)
googleImplementation(libs.dd.sdk.android.logs)
googleImplementation(libs.dd.sdk.android.rum)
googleImplementation(libs.dd.sdk.android.session.replay)
googleImplementation(libs.dd.sdk.android.session.replay.compose)
googleImplementation(libs.dd.sdk.android.timber)
googleImplementation(libs.dd.sdk.android.trace)
googleImplementation(libs.dd.sdk.android.trace.otel)
googleImplementation(platform(libs.firebase.bom))
googleImplementation(libs.firebase.analytics)
googleImplementation(libs.firebase.crashlytics)
googleApi(libs.dd.sdk.android.compose)
googleApi(libs.dd.sdk.android.logs)
googleApi(libs.dd.sdk.android.rum)
googleApi(libs.dd.sdk.android.session.replay)
googleApi(libs.dd.sdk.android.session.replay.compose)
googleApi(libs.dd.sdk.android.timber)
googleApi(libs.dd.sdk.android.trace)
googleApi(libs.dd.sdk.android.trace.otel)
googleApi(platform(libs.firebase.bom))
googleApi(libs.firebase.analytics)
googleApi(libs.firebase.crashlytics)
}
val googleServiceKeywords = listOf("crashlytics", "google", "datadog")

View File

@@ -213,6 +213,7 @@ room = { id = "androidx.room", version.ref = "room" }
spotless = { id = "com.diffplug.spotless", version = "8.1.0" }
# Meshtastic
meshtastic-analytics = { id = "meshtastic.analytics" }
meshtastic-android-application = { id = "meshtastic.android.application" }
meshtastic-android-application-compose = { id = "meshtastic.android.application.compose" }
meshtastic-android-application-flavors = { id = "meshtastic.android.application.flavors" }