From 149a345595624742ce1a2a27fb518a10f3a87b9a Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Tue, 22 Jul 2025 16:12:09 -0700 Subject: [PATCH 1/2] Move to a custom setup for BuildConfig.BACKEND_URL secrets gradle plugin is not Gradle project isolation compatible and is using deprecated AGP variant API. This change removes the usage by using a custom provider to set this value. Inspiration https://github.com/android/gradle-recipes/blob/agp-8.10/addCustomBuildConfigFields/build-logic/plugins/src/main/kotlin/CustomPlugin.kt https://github.com/android/nowinandroid/issues/1842 Test: ./gradlew core:network:assemble -> BuildConfig.java has correct value --- core/network/build.gradle.kts | 27 ++++++++++++++++++++++----- secrets.defaults.properties | 4 ---- 2 files changed, 22 insertions(+), 9 deletions(-) delete mode 100644 secrets.defaults.properties diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts index d12482a56..8fac106a9 100644 --- a/core/network/build.gradle.kts +++ b/core/network/build.gradle.kts @@ -14,12 +14,15 @@ * limitations under the License. */ +import com.android.build.api.variant.BuildConfigField +import java.io.StringReader +import java.util.Properties + plugins { alias(libs.plugins.nowinandroid.android.library) alias(libs.plugins.nowinandroid.android.library.jacoco) alias(libs.plugins.nowinandroid.hilt) id("kotlinx-serialization") - id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") } android { @@ -34,10 +37,6 @@ android { } } -secrets { - defaultPropertiesFileName = "secrets.defaults.properties" -} - dependencies { api(libs.kotlinx.datetime) api(projects.core.common) @@ -52,3 +51,21 @@ dependencies { testImplementation(libs.kotlinx.coroutines.test) } + +val backendUrl = providers.fileContents( + isolated.rootProject.projectDirectory.file("local.properties") +).asText.map { text -> + val properties = Properties() + properties.load(StringReader(text)) + if (properties.containsKey("BACKEND_URL")) + (properties["BACKEND_URL"] as String) + else "http://example.com" +}.orElse("http://example.com") + +androidComponents { + onVariants { + it.buildConfigFields.put("BACKEND_URL", backendUrl.map { value -> + BuildConfigField(type = "String", value = """"$value"""", comment = null) + }) + } +} diff --git a/secrets.defaults.properties b/secrets.defaults.properties deleted file mode 100644 index 3b5457bd9..000000000 --- a/secrets.defaults.properties +++ /dev/null @@ -1,4 +0,0 @@ -## This file provides default values to modules using the secrets-gradle-plugin. It is necessary -# because the secrets properties file is not under source control so CI builds will fail without -# default values. -BACKEND_URL="http://example.com" \ No newline at end of file From abac757e9f294e2139cdf6b69dabbb547075b2dc Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Mon, 28 Jul 2025 16:58:31 -0700 Subject: [PATCH 2/2] Add a comment for simplification --- core/network/build.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts index 8fac106a9..bf4dd9153 100644 --- a/core/network/build.gradle.kts +++ b/core/network/build.gradle.kts @@ -60,6 +60,7 @@ val backendUrl = providers.fileContents( if (properties.containsKey("BACKEND_URL")) (properties["BACKEND_URL"] as String) else "http://example.com" + // Move to returning `properties["BACKEND_URL"] as String?` after upgrading to Gradle 9.0.0 }.orElse("http://example.com") androidComponents {