From f366c1e607b64e57c08421ce7a6a47846eb2b78a Mon Sep 17 00:00:00 2001 From: Fadi George Date: Wed, 10 Jun 2026 00:02:42 -0700 Subject: [PATCH] chore: [SDK-4728] support gradle property override --- README.md | 8 +++++++- android/build.gradle | 12 +++++++++--- examples/demo-no-location/bun.lock | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5f7bf1fe..4cbbe976 100755 --- a/README.md +++ b/README.md @@ -42,6 +42,12 @@ ONESIGNAL_DISABLE_LOCATION=true pod install # iOS, from the ios directory ONESIGNAL_DISABLE_LOCATION=true ./gradlew assembleDebug # Android, from the android directory ``` +For Android, you can also persist the Gradle property in `android/gradle.properties`: + +```properties +onesignal.disableLocation=true +``` + In GitHub Actions, you can also set it once at the job or step level so `pod install`, `pod update`, and Gradle builds inherit it: @@ -63,7 +69,7 @@ rm -rf Pods Podfile.lock ONESIGNAL_DISABLE_LOCATION=true pod install ``` -Gradle re-reads the variable on each configuration, so a clean build with the variable set is enough on Android. +Gradle re-reads the environment variable or `onesignal.disableLocation` property on each configuration, so a clean build after changing the flag is enough on Android. > [!IMPORTANT] > When using Xcode or Android Studio, launch the IDE from a terminal that has `ONESIGNAL_DISABLE_LOCATION` exported. An IDE launched from the Dock/Finder does not inherit variables set only in your shell profile. On CI, key any CocoaPods / Gradle caches on the value of `ONESIGNAL_DISABLE_LOCATION` so a restored cache does not resurrect the location module. diff --git a/android/build.gradle b/android/build.gradle index 7ee3ca63..c6dc58e9 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,14 +5,20 @@ def safeExtGet(prop, fallback) { rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback } -def safeEnvFlagGet(prop) { - def value = System.getenv(prop) +def safeFlagGet(envProp, gradleProp) { + def value = System.getenv(envProp) + if (value == null && project.hasProperty(gradleProp)) { + value = project.property(gradleProp) + } + if (value == null && rootProject.hasProperty(gradleProp)) { + value = rootProject.property(gradleProp) + } def normalizedValue = value?.toString()?.trim() return normalizedValue != null && (normalizedValue.equalsIgnoreCase('true') || normalizedValue == '1') } def oneSignalVersion = '5.9.3' -def oneSignalDisableLocation = safeEnvFlagGet('ONESIGNAL_DISABLE_LOCATION') +def oneSignalDisableLocation = safeFlagGet('ONESIGNAL_DISABLE_LOCATION', 'onesignal.disableLocation') android { namespace "com.onesignal.rnonesignalandroid" diff --git a/examples/demo-no-location/bun.lock b/examples/demo-no-location/bun.lock index 40b044fc..e413f26a 100644 --- a/examples/demo-no-location/bun.lock +++ b/examples/demo-no-location/bun.lock @@ -898,7 +898,7 @@ "react-native-dotenv": ["react-native-dotenv@3.4.11", "", { "dependencies": { "dotenv": "^16.4.5" }, "peerDependencies": { "@babel/runtime": "^7.20.6" } }, "sha512-6vnIE+WHABSeHCaYP6l3O1BOEhWxKH6nHAdV7n/wKn/sciZ64zPPp2NUdEUf1m7g4uuzlLbjgr+6uDt89q2DOg=="], - "react-native-onesignal": ["react-native-onesignal@../../react-native-onesignal.tgz", { "dependencies": { "invariant": "^2.2.4" }, "peerDependencies": { "react-native": ">=0.79.0" } }, "sha512-W8nKFCwiiTq7yRopB/0MFeZDj+VFJCpkACU0An35asi0yAjJznlTuB+/eGXHA+X1CibcesgZr/+AIYGkhvvDAA=="], + "react-native-onesignal": ["react-native-onesignal@../../react-native-onesignal.tgz", { "dependencies": { "invariant": "^2.2.4" }, "peerDependencies": { "react-native": ">=0.79.0" } }, "sha512-Jm9JzhQ/yb9DBGhyJSpKmgOp8gOAhqqdeaXy4gmc88fRrR0YpHhzknA32sCVwMSqtK4FvqcVhxUP6ZnKxX9bxg=="], "react-refresh": ["react-refresh@0.14.2", "", {}, "sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA=="],