Skip to content

Commit 149a345

Browse files
committed
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 #1842 Test: ./gradlew core:network:assemble -> BuildConfig.java has correct value
1 parent ddf1647 commit 149a345

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

core/network/build.gradle.kts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17+
import com.android.build.api.variant.BuildConfigField
18+
import java.io.StringReader
19+
import java.util.Properties
20+
1721
plugins {
1822
alias(libs.plugins.nowinandroid.android.library)
1923
alias(libs.plugins.nowinandroid.android.library.jacoco)
2024
alias(libs.plugins.nowinandroid.hilt)
2125
id("kotlinx-serialization")
22-
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin")
2326
}
2427

2528
android {
@@ -34,10 +37,6 @@ android {
3437
}
3538
}
3639

37-
secrets {
38-
defaultPropertiesFileName = "secrets.defaults.properties"
39-
}
40-
4140
dependencies {
4241
api(libs.kotlinx.datetime)
4342
api(projects.core.common)
@@ -52,3 +51,21 @@ dependencies {
5251

5352
testImplementation(libs.kotlinx.coroutines.test)
5453
}
54+
55+
val backendUrl = providers.fileContents(
56+
isolated.rootProject.projectDirectory.file("local.properties")
57+
).asText.map { text ->
58+
val properties = Properties()
59+
properties.load(StringReader(text))
60+
if (properties.containsKey("BACKEND_URL"))
61+
(properties["BACKEND_URL"] as String)
62+
else "http://example.com"
63+
}.orElse("http://example.com")
64+
65+
androidComponents {
66+
onVariants {
67+
it.buildConfigFields.put("BACKEND_URL", backendUrl.map { value ->
68+
BuildConfigField(type = "String", value = """"$value"""", comment = null)
69+
})
70+
}
71+
}

secrets.defaults.properties

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)