From 0355c7b8b30efccbb1055cd6d8871e27a591f4d5 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Fri, 10 Apr 2026 10:18:02 -0500 Subject: [PATCH] fix(build): prevent DataDog asset transform from stripping fdroid release assets (#5044) --- app/proguard-rules.pro | 8 ++++++ .../main/kotlin/AnalyticsConventionPlugin.kt | 27 +++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 3db98de86..995f659ba 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -47,6 +47,14 @@ # R8 optimization for Kotlin null checks (AGP 9.0+) -processkotlinnullchecks remove +# Compose Multiplatform resources: keep the resource library internals and generated Res +# accessor classes so R8 does not tree-shake the resource loading infrastructure. +# Without these rules the fdroid flavor (which has fewer transitive Compose dependencies +# than google) crashes at startup with a misleading URLDecodeException due to R8 +# exception-class merging (see Koin keep rule above). +-keep class org.jetbrains.compose.resources.** { *; } +-keep class org.meshtastic.core.resources.** { *; } + # Nordic BLE -dontwarn no.nordicsemi.kotlin.ble.environment.android.mock.** -keep class no.nordicsemi.kotlin.ble.environment.android.mock.** { *; } diff --git a/build-logic/convention/src/main/kotlin/AnalyticsConventionPlugin.kt b/build-logic/convention/src/main/kotlin/AnalyticsConventionPlugin.kt index edf2d794a..046e3c4aa 100644 --- a/build-logic/convention/src/main/kotlin/AnalyticsConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/AnalyticsConventionPlugin.kt @@ -17,6 +17,7 @@ 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.InjectBuildIdToAssetsTask import com.datadog.gradle.plugin.InstrumentationMode import com.datadog.gradle.plugin.SdkCheckLevel import org.gradle.api.Plugin @@ -24,8 +25,10 @@ import org.gradle.api.Project import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.withType import org.meshtastic.buildlogic.libs import org.meshtastic.buildlogic.plugin +import java.io.File /** * Convention plugin for analytics (Google Services, Crashlytics, Datadog). Segregates these plugins to only affect the @@ -65,18 +68,38 @@ class AnalyticsConventionPlugin : Plugin { } } + // Disable Datadog analytics/upload tasks for fdroid, but NOT the buildId + // inject/generate tasks. The Datadog plugin wires InjectBuildIdToAssetsTask via + // variant.artifacts.toTransform(SingleArtifact.ASSETS), which replaces the merged + // assets artifact for the entire variant. Disabling that task leaves its output + // directory empty, causing compressAssets to produce zero files and stripping ALL + // assets (including Compose Multiplatform .cvr resources) from the release APK. plugins.withId("com.datadoghq.dd-sdk-android-gradle-plugin") { tasks.configureEach { if ( ( name.contains("datadog", ignoreCase = true) || - name.contains("uploadMapping", ignoreCase = true) || - name.contains("buildId", ignoreCase = true) + name.contains("uploadMapping", ignoreCase = true) ) && name.contains("fdroid", ignoreCase = true) ) { enabled = false } } + + // The inject task must stay enabled to maintain the AGP artifact pipeline, + // but we strip the datadog.buildId file from its output to preserve fdroid + // sterility — no analytics artifacts should ship in the open-source flavor. + tasks.withType().configureEach { + if (name.contains("Fdroid", ignoreCase = true)) { + doLast { + // Constant: GenerateBuildIdTask.BUILD_ID_FILE_NAME + val buildIdFile = File(outputAssets.get().asFile, "datadog.buildId") + if (buildIdFile.exists()) { + buildIdFile.delete() + } + } + } + } } // Configure variant-specific extensions.