Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-no-location/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading