From e3dd4325fdb06e6acc123cf511b31b3e42fa39f2 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Mon, 29 Sep 2025 11:51:07 -0500 Subject: [PATCH] fix(build): apply Datadog and Firebase plugins _only_ to google flavor (#3240) Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com> --- app/build.gradle.kts | 9 +++- build-logic/convention/build.gradle.kts | 5 +++ ...droidApplicationDatadogConventionPlugin.kt | 42 +++++++++++++++++++ ...roidApplicationFirebaseConventionPlugin.kt | 18 ++++---- ...droidApplicationFlavorsConventionPlugin.kt | 33 ++++++++++----- gradle/libs.versions.toml | 1 + 6 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 build-logic/convention/src/main/kotlin/AndroidApplicationDatadogConventionPlugin.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ab4421114..e6d175d84 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -25,12 +25,10 @@ plugins { alias(libs.plugins.meshtastic.android.application) alias(libs.plugins.meshtastic.android.application.flavors) alias(libs.plugins.meshtastic.android.application.compose) - alias(libs.plugins.meshtastic.android.application.firebase) alias(libs.plugins.meshtastic.hilt) alias(libs.plugins.kotlin.parcelize) alias(libs.plugins.meshtastic.kotlinx.serialization) alias(libs.plugins.devtools.ksp) - alias(libs.plugins.datadog) alias(libs.plugins.secrets) alias(libs.plugins.dokka) alias(libs.plugins.kover) @@ -131,6 +129,13 @@ android { ), ) ndk { abiFilters += listOf("armeabi-v7a", "arm64-v8a", "x86", "x86_64") } + + dependenciesInfo { + // Disables dependency metadata when building APKs (for IzzyOnDroid/F-Droid) + includeInApk = false + // Disables dependency metadata when building Android App Bundles (for Google Play) + includeInBundle = false + } } // Configure existing product flavors (defined by convention plugin) diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 72d93134b..1a9fe8c44 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -44,6 +44,7 @@ dependencies { compileOnly(libs.compose.gradlePlugin) compileOnly(libs.detekt.gradle) compileOnly(libs.firebase.crashlytics.gradlePlugin) + compileOnly(libs.firebase.performance.gradlePlugin) compileOnly(libs.kotlin.gradlePlugin) compileOnly(libs.ksp.gradlePlugin) compileOnly(libs.room.gradlePlugin) @@ -81,6 +82,10 @@ gradlePlugin { id = libs.plugins.meshtastic.android.application.firebase.get().pluginId implementationClass = "AndroidApplicationFirebaseConventionPlugin" } + register("androidDatadog") { + id = libs.plugins.meshtastic.android.application.datadog.get().pluginId + implementationClass = "AndroidApplicationDatadogConventionPlugin" + } register("androidLibraryCompose") { id = libs.plugins.meshtastic.android.library.compose.get().pluginId implementationClass = "AndroidLibraryComposeConventionPlugin" diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationDatadogConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationDatadogConventionPlugin.kt new file mode 100644 index 000000000..d061d659a --- /dev/null +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationDatadogConventionPlugin.kt @@ -0,0 +1,42 @@ +/* + * 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.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 + + +/** + * Convention plugin to apply and configure Datadog for Android applications. + * This plugin should only be applied to variants that require Datadog integration (e.g., 'google' flavor). + */ +class AndroidApplicationDatadogConventionPlugin : Plugin { + override fun apply(target: Project) { + with(target) { + extensions.configure { + apply(plugin = libs.findPlugin("datadog").get().get().pluginId) + dependencies { + "googleImplementation"(libs.findBundle("datadog").get()) + } + } + } + } +} diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationFirebaseConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationFirebaseConventionPlugin.kt index c6cc6cb6c..b1a4471de 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationFirebaseConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationFirebaseConventionPlugin.kt @@ -16,7 +16,6 @@ */ import com.android.build.api.dsl.ApplicationExtension -import com.geeksville.mesh.buildlogic.MeshtasticFlavor import com.geeksville.mesh.buildlogic.libs import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension import org.gradle.api.Plugin @@ -29,13 +28,14 @@ import org.gradle.kotlin.dsl.exclude class AndroidApplicationFirebaseConventionPlugin : Plugin { override fun apply(target: Project) { with(target) { - apply(plugin = "com.google.gms.google-services") - apply(plugin = "com.google.firebase.crashlytics") - + apply(plugin = libs.findPlugin("firebase-crashlytics").get().get().pluginId) + apply(plugin = libs.findPlugin("firebase-perf").get().get().pluginId) + apply(plugin = libs.findPlugin("google-services").get().get().pluginId) + extensions.configure { dependencies { val bom = libs.findLibrary("firebase-bom").get() - "implementation"(platform(bom)) - "implementation"(libs.findBundle("firebase").get()) { + "googleImplementation"(platform(bom)) + "googleImplementation"(libs.findBundle("firebase").get()) { /* Exclusion of protobuf / protolite dependencies is necessary as the datastore-proto brings in protobuf dependencies. These are the source of truth @@ -45,9 +45,13 @@ class AndroidApplicationFirebaseConventionPlugin : Plugin { exclude(group = "com.google.protobuf", module = "protobuf-java") exclude(group = "com.google.protobuf", module = "protobuf-kotlin") exclude(group = "com.google.protobuf", module = "protobuf-javalite") - exclude(group = "com.google.firebase", module = "protolite-well-known-types") + exclude( + group = "com.google.firebase", + module = "protolite-well-known-types" + ) } } + } extensions.configure { buildTypes.configureEach { diff --git a/build-logic/convention/src/main/kotlin/AndroidApplicationFlavorsConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AndroidApplicationFlavorsConventionPlugin.kt index 36945f951..4dbfa0f1d 100644 --- a/build-logic/convention/src/main/kotlin/AndroidApplicationFlavorsConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AndroidApplicationFlavorsConventionPlugin.kt @@ -16,10 +16,12 @@ */ import com.android.build.api.dsl.ApplicationExtension +import com.geeksville.mesh.buildlogic.MeshtasticFlavor import com.geeksville.mesh.buildlogic.configureFlavors 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 import org.gradle.kotlin.dsl.exclude @@ -29,17 +31,28 @@ class AndroidApplicationFlavorsConventionPlugin : Plugin { with(target) { extensions.configure { configureFlavors(this) - dependencies { - // F-Droid specific dependencies - "fdroidImplementation"(libs.findBundle("osm").get()) - "fdroidImplementation"(libs.findLibrary("osmdroid-geopackage").get()) { - exclude(group = "com.j256.ormlite") + productFlavors { + all { + if (name == MeshtasticFlavor.google.name) { + apply(plugin = "meshtastic.android.application.firebase") + apply(plugin = "meshtastic.android.application.datadog") + dependencies { + // Google specific dependencies + "googleImplementation"(libs.findBundle("maps-compose").get()) + "googleImplementation"(libs.findLibrary("awesome-app-rating").get()) + } + } else if (name == MeshtasticFlavor.fdroid.name) { + dependencies { + // F-Droid specific dependencies + "fdroidImplementation"(libs.findBundle("osm").get()) + "fdroidImplementation"( + libs.findLibrary("osmdroid-geopackage").get() + ) { + exclude(group = "com.j256.ormlite") + } + } + } } - - // Google specific dependencies - "googleImplementation"(libs.findBundle("maps-compose").get()) - "googleImplementation"(libs.findLibrary("awesome-app-rating").get()) - "googleImplementation"(libs.findBundle("datadog").get()) } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 01de6b43d..365c39a92 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -251,6 +251,7 @@ spotless = { id = "com.diffplug.spotless", version = "8.0.0" } # Meshtastic meshtastic-android-application = { id = "meshtastic.android.application" } meshtastic-android-application-compose = { id = "meshtastic.android.application.compose" } +meshtastic-android-application-datadog = { id = "meshtastic.android.application.datadog" } meshtastic-android-application-firebase = { id = "meshtastic.android.application.firebase" } meshtastic-android-application-flavors = { id = "meshtastic.android.application.flavors" } meshtastic-android-library = { id = "meshtastic.android.library" }