From fdff7315fef52b8f4a91a2c7c79ce31af61a002c Mon Sep 17 00:00:00 2001
From: James Rich <2199651+jamesarich@users.noreply.github.com>
Date: Wed, 10 Dec 2025 22:47:25 -0600
Subject: [PATCH] refactor(build): Create a dedicated analytics convention
plugin (#3961)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
---
app/build.gradle.kts | 7 ---
build-logic/convention/build.gradle.kts | 4 ++
.../main/kotlin/AnalyticsConventionPlugin.kt | 61 +++++++++++++++++++
.../AndroidApplicationConventionPlugin.kt | 3 +-
core/analytics/build.gradle.kts | 22 +++----
gradle/libs.versions.toml | 1 +
6 files changed, 78 insertions(+), 20 deletions(-)
create mode 100644 build-logic/convention/src/main/kotlin/AnalyticsConventionPlugin.kt
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 9f1f8e51f..d376b4e18 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -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" }
}
diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts
index 3a696aa7f..3860338eb 100644
--- a/build-logic/convention/build.gradle.kts
+++ b/build-logic/convention/build.gradle.kts
@@ -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"
diff --git a/build-logic/convention/src/main/kotlin/AnalyticsConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AnalyticsConventionPlugin.kt
new file mode 100644
index 000000000..6546c7f29
--- /dev/null
+++ b/build-logic/convention/src/main/kotlin/AnalyticsConventionPlugin.kt
@@ -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 .
+ */
+
+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 {
+ override fun apply(target: Project) {
+ with(target) {
+ extensions.configure {
+ 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 {
+ onVariants { variant ->
+ if (variant.flavorName == "google") {
+ extensions.configure {
+ variants {
+ register(variant.name) {
+ site = "US5"
+ composeInstrumentation = InstrumentationMode.AUTO
+ }
+ }
+ checkProjectDependencies = SdkCheckLevel.NONE
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt
index c8e6901f7..7fed93657 100644
--- a/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt
+++ b/build-logic/convention/src/main/kotlin/AndroidApplicationConventionPlugin.kt
@@ -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 {
override fun apply(target: Project) {
@@ -33,6 +31,7 @@ class AndroidApplicationConventionPlugin : Plugin {
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 {
diff --git a/core/analytics/build.gradle.kts b/core/analytics/build.gradle.kts
index 6a649a49c..fff87e61e 100644
--- a/core/analytics/build.gradle.kts
+++ b/core/analytics/build.gradle.kts
@@ -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")
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index f1981da3d..a184cbd7b 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -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" }