diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 889b8137..1fc2ac13 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -49,7 +49,7 @@ jobs: - name: Resolve OneSignal Android SDK version id: android-sdk-version run: | - VERSION=$(grep "com.onesignal:OneSignal:" android/build.gradle | sed -E "s/.*OneSignal:([^\"']+).*/\1/") + VERSION=$(grep "def oneSignalVersion =" android/build.gradle | sed -E "s/.*= ['\"]([^'\"]+)['\"].*/\1/") echo "version=${VERSION}" >> "$GITHUB_OUTPUT" - name: Wait for OneSignal Android SDK on Maven Central diff --git a/README.md b/README.md index 49aaa3f6..6aae764f 100755 --- a/README.md +++ b/README.md @@ -35,20 +35,39 @@ See the [Setup Guide](https://documentation.onesignal.com/docs/react-native-sdk- By default, `react-native-onesignal` includes OneSignal's native location module so `OneSignal.Location` works without extra setup. If your app does not use location features, you can exclude the native location module from iOS and Android builds. -In your iOS `Podfile`, set this before React Native installs native modules: +Set `ONESIGNAL_DISABLE_LOCATION=true` in the environment before resolving or building, for both CocoaPods (iOS) and Gradle (Android): -```ruby -$OneSignalDisableLocation = true +```sh +ONESIGNAL_DISABLE_LOCATION=true pod install # iOS, from the ios directory +ONESIGNAL_DISABLE_LOCATION=true ./gradlew assembleDebug # Android, from the android directory ``` -In your Android `gradle.properties`, set: +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: -```properties -OneSignal_disableLocation=true +```yaml +env: + ONESIGNAL_DISABLE_LOCATION: true ``` When disabled, `OneSignal.Location.requestPermission()` and `OneSignal.Location.setShared()` no-op on native builds without the location module, and `OneSignal.Location.isShared()` resolves `false`. +##### Applying the change (clearing cached pods) + +The environment variable is only read when dependencies are **resolved**. CocoaPods pins the resolved pods in `Podfile.lock`, so after changing the variable on an existing project you must reinstall pods in a shell where the variable is exported: + +```sh +cd ios +pod deintegrate +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. + +> [!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. + #### Change Log See this repository's [release tags](https://github.com/OneSignal/react-native-onesignal/releases) for a complete change log of every released version. diff --git a/android/build.gradle b/android/build.gradle index e43cc2f4..201bfa39 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,17 +5,13 @@ def safeExtGet(prop, fallback) { rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback } -def safePropGet(prop, fallback) { - if (rootProject.ext.has(prop)) { - return rootProject.ext.get(prop) - } - - def value = rootProject.findProperty(prop) - return value != null ? value : fallback +def safeEnvFlagGet(prop) { + def value = System.getenv(prop) + return value != null && value.toString().toBoolean() } def oneSignalVersion = '5.9.3' -def oneSignalDisableLocation = safePropGet('OneSignal_disableLocation', false).toString().toBoolean() +def oneSignalDisableLocation = safeEnvFlagGet('ONESIGNAL_DISABLE_LOCATION') android { namespace "com.onesignal.rnonesignalandroid" diff --git a/examples/demo-no-location/README.md b/examples/demo-no-location/README.md index 54cdd2c6..63c32019 100644 --- a/examples/demo-no-location/README.md +++ b/examples/demo-no-location/README.md @@ -9,24 +9,34 @@ vp run ios vp run android ``` +Both platforms exclude the native location module by setting the +`ONESIGNAL_DISABLE_LOCATION=true` environment variable when dependencies are +resolved. + ## iOS -The CocoaPods flag is set before `use_native_modules!` installs React Native pods: +The `pods` and `update:pods` scripts in `package.json` export the variable so +CocoaPods resolves OneSignal without the location subspec: -```ruby -$OneSignalDisableLocation = true +```sh +ONESIGNAL_DISABLE_LOCATION=true bundle exec pod install ``` -See `ios/Podfile`. +If you run `pod install` or `pod update` manually, set +`ONESIGNAL_DISABLE_LOCATION=true` in that shell too. ## Android -The Gradle property is set in `android/gradle.properties`: +The `android` script in `package.json` exports the variable so Gradle resolves +OneSignal without the location module: -```properties -OneSignal_disableLocation=true +```sh +ONESIGNAL_DISABLE_LOCATION=true bash ../run-android.sh ``` +If you build Android another way (Android Studio, a raw `./gradlew` invocation), +set `ONESIGNAL_DISABLE_LOCATION=true` in that environment too. + ## App Code `App.tsx` initializes OneSignal and requests notification permission without calling the `OneSignal.Location` namespace. With the native flags enabled, the build excludes the native OneSignal location module. diff --git a/examples/demo-no-location/android/app/src/main/java/com/demo/MainActivity.kt b/examples/demo-no-location/android/app/src/main/java/com/demo/MainActivity.kt deleted file mode 100644 index 037316ec..00000000 --- a/examples/demo-no-location/android/app/src/main/java/com/demo/MainActivity.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.demo - -import com.facebook.react.ReactActivity -import com.facebook.react.ReactActivityDelegate -import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled -import com.facebook.react.defaults.DefaultReactActivityDelegate - -class MainActivity : ReactActivity() { - - /** - * Returns the name of the main component registered from JavaScript. This is used to schedule - * rendering of the component. - */ - override fun getMainComponentName(): String = "demo" - - /** - * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] - * which allows you to enable New Architecture with a single boolean flags [fabricEnabled] - */ - override fun createReactActivityDelegate(): ReactActivityDelegate = - DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) -} diff --git a/examples/demo-no-location/android/app/src/main/java/com/demo/MainApplication.kt b/examples/demo-no-location/android/app/src/main/java/com/demo/MainApplication.kt deleted file mode 100644 index b6d53e31..00000000 --- a/examples/demo-no-location/android/app/src/main/java/com/demo/MainApplication.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.demo - -import android.app.Application -import com.facebook.react.PackageList -import com.facebook.react.ReactApplication -import com.facebook.react.ReactHost -import com.facebook.react.ReactNativeApplicationEntryPoint.loadReactNative -import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost - -class MainApplication : Application(), ReactApplication { - - override val reactHost: ReactHost by lazy { - getDefaultReactHost( - context = applicationContext, - packageList = - PackageList(this).packages.apply { - // Packages that cannot be autolinked yet can be added manually here, for example: - // add(MyReactNativePackage()) - }, - ) - } - - override fun onCreate() { - super.onCreate() - loadReactNative(this) - } -} diff --git a/examples/demo-no-location/android/app/src/main/res/raw/vine_boom.wav b/examples/demo-no-location/android/app/src/main/res/raw/vine_boom.wav deleted file mode 100644 index 626bd5cc..00000000 Binary files a/examples/demo-no-location/android/app/src/main/res/raw/vine_boom.wav and /dev/null differ diff --git a/examples/demo-no-location/android/gradle.properties b/examples/demo-no-location/android/gradle.properties index a45a3933..cf10d482 100644 --- a/examples/demo-no-location/android/gradle.properties +++ b/examples/demo-no-location/android/gradle.properties @@ -42,6 +42,3 @@ hermesEnabled=true # This allows your app to draw behind system bars for an immersive UI. # Note: Only works with ReactActivity and should not be used with custom Activity. edgeToEdgeEnabled=false - -# Exclude OneSignal's native location module from Android builds. -OneSignal_disableLocation=true diff --git a/examples/demo-no-location/bun.lock b/examples/demo-no-location/bun.lock index ae0ac80a..464cfa17 100644 --- a/examples/demo-no-location/bun.lock +++ b/examples/demo-no-location/bun.lock @@ -5,9 +5,9 @@ "": { "name": "demo-no-location", "dependencies": { + "react-native-onesignal": "file:../../react-native-onesignal.tgz", "react": "19.2.3", "react-native": "0.84.0", - "react-native-onesignal": "file:../../react-native-onesignal.tgz", }, "devDependencies": { "@babel/core": "^7.25.2", @@ -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-hAoOac1avBaHhG4Hxf+vJO75tZ7plc0sVp9pHghwv+Prs46BYjgSnWjRmrC2E+Ekgi3fKH/H4CiPCq4MZGjIgg=="], + "react-native-onesignal": ["react-native-onesignal@../../react-native-onesignal.tgz", { "dependencies": { "invariant": "^2.2.4" }, "peerDependencies": { "react-native": ">=0.79.0" } }, "sha512-zzX4NLvrxAzPX4uTVgZdm4rf6ljjOcbNBgcXkJuMLqW6TzIXLyx1DtrcHAkQbrN1WK4RlfVBU2UXgPHePtCykA=="], "react-refresh": ["react-refresh@0.14.2", "", {}, "sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA=="], diff --git a/examples/demo-no-location/ios/Podfile b/examples/demo-no-location/ios/Podfile index 1cb23be7..e767f599 100644 --- a/examples/demo-no-location/ios/Podfile +++ b/examples/demo-no-location/ios/Podfile @@ -1,4 +1,3 @@ -$OneSignalDisableLocation = true # Resolve react_native_pods.rb with node to allow for hoisting require Pod::Executable.execute_command('node', ['-p', 'require.resolve( diff --git a/examples/demo-no-location/ios/Podfile.lock b/examples/demo-no-location/ios/Podfile.lock index e27e2718..508fc8eb 100644 --- a/examples/demo-no-location/ios/Podfile.lock +++ b/examples/demo-no-location/ios/Podfile.lock @@ -2158,6 +2158,6 @@ SPEC CHECKSUMS: ReactNativeDependencies: 247df240f5ecafe765afbfba15da0a8daa4a2985 Yoga: 772166513f9cd2d61a6251d0dacbbfaa5b537479 -PODFILE CHECKSUM: c3ac62d933cd818342aa59fcf882cd94a6cd1af2 +PODFILE CHECKSUM: f3189232211372e657ece2d9f66c621325fb421a -COCOAPODS: 1.15.2 +COCOAPODS: 1.16.2 diff --git a/examples/demo-no-location/ios/demo.xcodeproj/project.pbxproj b/examples/demo-no-location/ios/demo.xcodeproj/project.pbxproj index 53892638..97e4f62a 100644 --- a/examples/demo-no-location/ios/demo.xcodeproj/project.pbxproj +++ b/examples/demo-no-location/ios/demo.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ 5F8F7D5C84F8947D278D5B06 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */; }; 761780ED2CA45674006654EE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 761780EC2CA45674006654EE /* AppDelegate.swift */; }; 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; - B10000000000000000000001 /* vine_boom.wav in Resources */ = {isa = PBXBuildFile; fileRef = B20000000000000000000001 /* vine_boom.wav */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -55,7 +54,6 @@ A2000000000000000000000F /* libPods-OneSignalNotificationServiceExtension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OneSignalNotificationServiceExtension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; A20000000000000000000010 /* libPods-OneSignalWidgetExtension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OneSignalWidgetExtension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; A20000000000000000000011 /* demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = demo.entitlements; path = demo/demo.entitlements; sourceTree = ""; }; - B20000000000000000000001 /* vine_boom.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = vine_boom.wav; path = demo/vine_boom.wav; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -80,7 +78,6 @@ 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */, 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */, A20000000000000000000011 /* demo.entitlements */, - B20000000000000000000001 /* vine_boom.wav */, ); name = demo; sourceTree = ""; @@ -234,7 +231,6 @@ 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, 5F8F7D5C84F8947D278D5B06 /* PrivacyInfo.xcprivacy in Resources */, - B10000000000000000000001 /* vine_boom.wav in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/examples/demo-no-location/package.json b/examples/demo-no-location/package.json index 5129470c..2c894442 100644 --- a/examples/demo-no-location/package.json +++ b/examples/demo-no-location/package.json @@ -6,10 +6,10 @@ "setup": "../setup.sh", "preandroid": "vp run setup", "preios": "vp run setup && vp run pods", - "android": "bash ../run-android.sh", + "android": "ONESIGNAL_DISABLE_LOCATION=true bash ../run-android.sh", "ios": "bash ../run-ios.sh", - "pods": "bundle install && (cd ios && bundle exec pod install)", - "update:pods": "(cd ios && pod update OneSignalXCFramework --no-repo-update)", + "pods": "bundle install && (cd ios && ONESIGNAL_DISABLE_LOCATION=true bundle exec pod install)", + "update:pods": "(cd ios && ONESIGNAL_DISABLE_LOCATION=true pod update OneSignalXCFramework --no-repo-update)", "clean:android": "rm -rf android/app/build android/app/.cxx android/build && adb uninstall com.onesignal.example >/dev/null 2>&1 || true", "clean:ios": "rm -rf ios/build ios/Pods", "start": "react-native start" diff --git a/react-native-onesignal.podspec b/react-native-onesignal.podspec index 56c39992..70c9fe7f 100644 --- a/react-native-onesignal.podspec +++ b/react-native-onesignal.podspec @@ -1,7 +1,7 @@ require 'json' package_json = JSON.parse(File.read('package.json')) onesignal_xcframework_version = '5.5.2' -onesignal_disable_location = defined?($OneSignalDisableLocation) && $OneSignalDisableLocation == true +onesignal_disable_location = ENV['ONESIGNAL_DISABLE_LOCATION'] == 'true' Pod::Spec.new do |s| s.name = "react-native-onesignal"