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
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
unityVersion: 6000.4.11f1
targetPlatform: Android
buildMethod: BuildScript.BuildAndroidEmulator
customParameters: -demoBundleId com.onesignal.sdkdemo
allowDirtyBuild: true
# Run the Docker build as the runner's host user so the Library
# folder is owned by the runner and actions/cache can tar it in
Expand Down Expand Up @@ -164,6 +165,7 @@ jobs:
unityVersion: 6000.4.11f1
targetPlatform: iOS
buildMethod: BuildScript.BuildiOSDevice
customParameters: -demoBundleId com.onesignal.sdkdemo -demoTeamId DL8TF3X4K3
allowDirtyBuild: true
cacheUnityInstallationOnMac: true

Expand Down
4 changes: 2 additions & 2 deletions examples/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ In `AppViewModel.LoadInitialState()` (`AppViewModel.cs` lines ~110-122), UI stat
### Environment / secrets
- `Assets/StreamingAssets/.env` is loaded at startup via `DotEnv.Load()` (`Assets/Scripts/Services/DotEnv.cs`). In the Editor, `DotEnv` reads `<project>/.env` directly; on Android it reads via `AssetManager.open(".env")`.
- Recognized keys: `ONESIGNAL_APP_ID`, `ONESIGNAL_API_KEY`, `ONESIGNAL_ANDROID_CHANNEL_ID`, `E2E_MODE`.
- `AppBootstrapper.Start()` calls `DotEnv.Load()` BEFORE `OneSignal.Initialize`. There is no default App ID: `CopyEnvPreBuild` fails the build when `ONESIGNAL_APP_ID` is missing from `.env`, and `AppBootstrapper` throws if it is empty at runtime.
- `AppBootstrapper.Start()` calls `DotEnv.Load()` BEFORE `OneSignal.Initialize`. `CopyEnvPreBuild` copies `.env` into StreamingAssets when it exists. When `ONESIGNAL_APP_ID` is missing or empty, `AppBootstrapper` uses the shared example app `1154c350-e715-4b71-a58b-1b84b6745baa`.

### Android package and Firebase
- Android package and iOS bundle ID are `com.onesignal.sdkdemo`.
- Android package and iOS bundle ID default to `com.onesignal.example` (Apple team `99SW8E36CT`) in `ProjectSettings.asset`. `BuildScript` accepts `-demoBundleId` / `-demoTeamId` to override them for one build and restores the originals afterwards; E2E passes `com.onesignal.sdkdemo` / `DL8TF3X4K3`. `SigningPostProcessor` uses the resulting team for every target and suffixes the NSE / widget bundle IDs with `.NSE` / `.LA`.
- `mainTemplate.gradle` depends on `com.google.firebase:firebase-messaging:25.1.3`.
- `google-services.json` lives in the project root and is gitignored. `FirebaseInstallationIdBuild` copies it into the generated `launcher/` module, where `launcherTemplate.gradle` applies the Google Services plugin only when the file exists (`baseProjectTemplate.gradle` declares the plugin version).
- The `firebase_messaging_installation_id_enabled` meta-data in `Assets/Plugins/Android/AndroidManifest.xml` defaults to `false`. The `FIREBASE_INSTALLATION_ID_ENABLED` scripting define (set in `Assets/csc.rsp` by E2E) flips it to `true` and fails the build if `google-services.json` is missing.
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-no-location/Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4e1e7c96909144afa42b3fb595db18f0, type: 3}
m_Name:
m_EditorClassIdentifier:
_oneSignalAppId: YOUR-ONESIGNAL-APP-ID
_oneSignalAppId: 1154c350-e715-4b71-a58b-1b84b6745baa
--- !u!1660057539 &9223372036854775807
SceneRoots:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public sealed class NoLocationDemo : MonoBehaviour
{
[SerializeField]
private string _oneSignalAppId = "YOUR-ONESIGNAL-APP-ID";
private string _oneSignalAppId = "1154c350-e715-4b71-a58b-1b84b6745baa";

private const float ReferenceWidth = 393f;
private const string DemoAndroidGroup = "demo-group";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<files />
<settings>
<setting name="androidAbis" value="arm64-v8a" />
<setting name="bundleId" value="com.onesignal.sdkdemo" />
<setting name="bundleId" value="com.onesignal.example" />
<setting name="explodeAars" value="True" />
<setting name="gradleBuildEnabled" value="True" />
<setting name="gradlePropertiesTemplateEnabled" value="True" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ PlayerSettings:
androidMaxAspectRatio: 2.4
androidMinAspectRatio: 1
applicationIdentifier:
Android: com.onesignal.sdkdemo
iPhone: com.onesignal.sdkdemo
Android: com.onesignal.example
iPhone: com.onesignal.example
buildNumber:
Standalone: 0
VisionOS: 0
Expand Down Expand Up @@ -241,7 +241,7 @@ PlayerSettings:
metalCompileShaderBinary: 0
iOSRenderExtraFrameOnPause: 1
iosCopyPluginsCodeInsteadOfSymlink: 0
appleDeveloperTeamID:
appleDeveloperTeamID: 99SW8E36CT
iOSManualSigningProvisioningProfileID:
tvOSManualSigningProvisioningProfileID:
VisionOSManualSigningProvisioningProfileID:
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-no-location/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ For Play Mode in the Unity Editor:
2. Select the `OneSignal No Location Demo` GameObject.
3. Set `One Signal App Id` on the `NoLocationDemo` component.

If the value is left as `YOUR-ONESIGNAL-APP-ID`, the app starts but does not initialize OneSignal.
The scene ships with the shared example app `1154c350-e715-4b71-a58b-1b84b6745baa`, so the app initializes OneSignal without any setup.

## Run On Android

Expand Down
2 changes: 1 addition & 1 deletion examples/demo-no-location/run-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ if [ "$INSTALL" = true ] && [ -n "$EMULATOR" ]; then
"$ADB" -s "$EMULATOR" wait-for-device
echo "Installing on $EMULATOR..."
"$ADB" -s "$EMULATOR" install -r "$OUTPUT"
"$ADB" -s "$EMULATOR" shell am start -n com.onesignal.sdkdemo/com.unity3d.player.UnityPlayerActivity
"$ADB" -s "$EMULATOR" shell am start -n com.onesignal.example/com.unity3d.player.UnityPlayerActivity
fi
2 changes: 1 addition & 1 deletion examples/demo-no-location/run-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ XCODE_DIR="$SCRIPT_DIR/Build/iOS"
LOG="$SCRIPT_DIR/Build/build-ios.log"
SCHEME="Unity-iPhone"
DERIVED="$SCRIPT_DIR/Build/iOS-DerivedData"
APP_BUNDLE_ID="com.onesignal.sdkdemo"
APP_BUNDLE_ID="com.onesignal.example"
INSTALL=true
SKIP_BUILD=false
OPEN_XCODE=false
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Required. The build fails without it.
# Optional. Leave empty to use the shared example app.
ONESIGNAL_APP_ID=
ONESIGNAL_API_KEY=your_rest_api_key
E2E_MODE=false
Expand Down
21 changes: 14 additions & 7 deletions examples/demo/Assets/App/Editor/iOS/SigningPostProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ namespace App.Editor.iOS
/// </summary>
public class SigningPostProcessor : IPostprocessBuildWithReport
{
private const string AppleTeamId = "DL8TF3X4K3";

private const string NseTargetName = "OneSignalNotificationServiceExtension";
private const string WidgetTargetName = "OneSignalWidgetExtension";

Expand Down Expand Up @@ -106,36 +104,44 @@ private static void FixupSigningAndBundleIds(string outputPath)
project.ReadFromString(File.ReadAllText(projectPath));

var appId = PlayerSettings.GetApplicationIdentifier(NamedBuildTarget.iOS);
var teamId = PlayerSettings.iOS.appleDeveloperTeamID;
var manualSigning = IsCiBuild();

var mainGuid = project.GetUnityMainTargetGuid();
ApplyTeamId(project, mainGuid, "Unity-iPhone");
ApplyTeamId(project, mainGuid, teamId, "Unity-iPhone");
if (manualSigning)
ApplyManualSigning(project, mainGuid, MainProfileName, "Unity-iPhone");

ApplyExtensionFixup(
project,
NseTargetName,
$"{appId}.{NseBundleSuffix}",
teamId,
manualSigning ? NseProfileName : null
);
ApplyExtensionFixup(
project,
WidgetTargetName,
$"{appId}.{WidgetBundleSuffix}",
teamId,
manualSigning ? WidgetProfileName : null
);

File.WriteAllText(projectPath, project.WriteToString());
}

private static void ApplyTeamId(PBXProject project, string targetGuid, string label)
private static void ApplyTeamId(
PBXProject project,
string targetGuid,
string teamId,
string label
)
{
if (string.IsNullOrEmpty(targetGuid))
return;

project.SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", AppleTeamId);
Debug.Log($"[SigningPostProcessor] Pinned DEVELOPMENT_TEAM={AppleTeamId} on {label}");
project.SetBuildProperty(targetGuid, "DEVELOPMENT_TEAM", teamId);
Debug.Log($"[SigningPostProcessor] Pinned DEVELOPMENT_TEAM={teamId} on {label}");
}

private static void ApplyManualSigning(
Expand Down Expand Up @@ -170,6 +176,7 @@ private static void ApplyExtensionFixup(
PBXProject project,
string targetName,
string bundleId,
string teamId,
string profileName
)
{
Expand All @@ -183,7 +190,7 @@ string profileName
}

project.SetBuildProperty(guid, "PRODUCT_BUNDLE_IDENTIFIER", bundleId);
ApplyTeamId(project, guid, targetName);
ApplyTeamId(project, guid, teamId, targetName);
if (!string.IsNullOrEmpty(profileName))
ApplyManualSigning(project, guid, profileName, targetName);
Debug.Log(
Expand Down
7 changes: 2 additions & 5 deletions examples/demo/Assets/Scripts/AppBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace OneSignalDemo
public class AppBootstrapper : MonoBehaviour
{
private const string Tag = "AppBootstrapper";
private const string DefaultAppId = "1154c350-e715-4b71-a58b-1b84b6745baa";

[SerializeField]
private AppViewModel _viewModel;
Expand Down Expand Up @@ -50,11 +51,7 @@ private async void Start()

var appId = DotEnv.Get("ONESIGNAL_APP_ID").Trim();
if (string.IsNullOrEmpty(appId))
{
throw new InvalidOperationException(
"ONESIGNAL_APP_ID is not set. Add it to examples/demo/.env."
);
}
appId = DefaultAppId;

_apiService.SetAppId(appId);

Expand Down
47 changes: 44 additions & 3 deletions examples/demo/Assets/Scripts/Editor/BuildScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,47 @@ public static class BuildScript
private const string ApkName = "onesignal-demo.apk";
private const string IOSOutputDir = "Build/iOS";

/// <summary>
/// Builds with the given bundle ID and Apple team instead of the defaults in
/// ProjectSettings (com.onesignal.example / 99SW8E36CT), then restores them so
/// the override never lands in ProjectSettings.asset. E2E passes
/// <c>-demoBundleId com.onesignal.sdkdemo -demoTeamId DL8TF3X4K3</c>.
/// </summary>
private static BuildReport BuildWithDemoIdentity(BuildPlayerOptions options)
{
var target = options.target == BuildTarget.iOS ? NamedBuildTarget.iOS : NamedBuildTarget.Android;
var originalBundleId = PlayerSettings.GetApplicationIdentifier(target);
var originalTeamId = PlayerSettings.iOS.appleDeveloperTeamID;

var bundleId = GetArg("-demoBundleId");
if (!string.IsNullOrEmpty(bundleId))
PlayerSettings.SetApplicationIdentifier(target, bundleId);
var teamId = GetArg("-demoTeamId");
if (!string.IsNullOrEmpty(teamId))
PlayerSettings.iOS.appleDeveloperTeamID = teamId;

Debug.Log(
$"[BuildScript] bundleId={PlayerSettings.GetApplicationIdentifier(target)} teamId={PlayerSettings.iOS.appleDeveloperTeamID}"
);

try
{
return BuildPipeline.BuildPlayer(options);
}
finally
{
PlayerSettings.SetApplicationIdentifier(target, originalBundleId);
PlayerSettings.iOS.appleDeveloperTeamID = originalTeamId;
}
}

private static string GetArg(string name)
{
var args = Environment.GetCommandLineArgs();
var index = Array.IndexOf(args, name);
return index >= 0 && index + 1 < args.Length ? args[index + 1].Trim() : null;
}

/// <summary>
/// Builds an Android APK using the architecture and scripting backend
/// pre-configured in ProjectSettings.asset by run-android.sh.
Expand Down Expand Up @@ -61,7 +102,7 @@ public static void BuildAndroidEmulator()
options = BuildOptions.None,
};

var report = BuildPipeline.BuildPlayer(options);
var report = BuildWithDemoIdentity(options);
HandleReport(report, outputPath);
}

Expand Down Expand Up @@ -105,7 +146,7 @@ public static void BuildiOSSimulator()
options = BuildOptions.None,
};

var report = BuildPipeline.BuildPlayer(options);
var report = BuildWithDemoIdentity(options);
HandleReport(report, IOSOutputDir);
}

Expand Down Expand Up @@ -148,7 +189,7 @@ public static void BuildiOSDevice()
options = BuildOptions.None,
};

var report = BuildPipeline.BuildPlayer(options);
var report = BuildWithDemoIdentity(options);
HandleReport(report, IOSOutputDir);
}

Expand Down
18 changes: 8 additions & 10 deletions examples/demo/Assets/Scripts/Editor/CopyEnvPreBuild.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
Expand All @@ -8,11 +7,6 @@ namespace OneSignalDemo.Editor
{
public class CopyEnvPreBuild : IPreprocessBuildWithReport
{
private static readonly Regex AppIdLine = new Regex(
@"^[ \t]*ONESIGNAL_APP_ID[ \t]*=[ \t]*[^\s#]",
RegexOptions.Multiline
);

public int callbackOrder => 0;

public void OnPreprocessBuild(BuildReport report)
Expand All @@ -21,11 +15,15 @@ public void OnPreprocessBuild(BuildReport report)
var source = Path.Combine(projectRoot, ".env");
var dest = Path.Combine(Application.streamingAssetsPath, ".env");

if (!File.Exists(source) || !AppIdLine.IsMatch(File.ReadAllText(source)))
// Without a .env the app falls back to the shared example app; drop any
// copy left by an earlier build so it doesn't keep stale values.
if (!File.Exists(source))
{
throw new BuildFailedException(
"ONESIGNAL_APP_ID is not set. Add it to examples/demo/.env."
);
foreach (var path in new[] { dest, dest + ".meta" })
if (File.Exists(path))
File.Delete(path);
Debug.Log("[OneSignalDemo] No .env; using the default app ID");
return;
}

Directory.CreateDirectory(Application.streamingAssetsPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<files />
<settings>
<setting name="androidAbis" value="arm64-v8a" />
<setting name="bundleId" value="com.onesignal.sdkdemo" />
<setting name="bundleId" value="com.onesignal.example" />
<setting name="explodeAars" value="True" />
<setting name="gradleBuildEnabled" value="True" />
<setting name="gradlePropertiesTemplateEnabled" value="True" />
Expand Down
6 changes: 3 additions & 3 deletions examples/demo/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ PlayerSettings:
androidMaxAspectRatio: 2.1
androidMinAspectRatio: 1
applicationIdentifier:
Android: com.onesignal.sdkdemo
iPhone: com.onesignal.sdkdemo
Android: com.onesignal.example
iPhone: com.onesignal.example
buildNumber:
Standalone: 0
VisionOS: 0
Expand Down Expand Up @@ -241,7 +241,7 @@ PlayerSettings:
metalCompileShaderBinary: 0
iOSRenderExtraFrameOnPause: 0
iosCopyPluginsCodeInsteadOfSymlink: 0
appleDeveloperTeamID:
appleDeveloperTeamID: 99SW8E36CT
iOSManualSigningProvisioningProfileID:
tvOSManualSigningProvisioningProfileID:
VisionOSManualSigningProvisioningProfileID:
Expand Down
8 changes: 4 additions & 4 deletions examples/demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A Unity app showcasing OneSignal Unity SDK features including push notifications, in-app messaging, user management, tags, triggers, outcomes, live activities, and more. It references the in-repo UPM packages (`com.onesignal.unity.core`, `.android`, `.ios`) through `file:` paths in `Packages/manifest.json`.

The demo uses the bundle ID `com.onesignal.sdkdemo` on Android and iOS. It is for repository development and testing. The user-facing sample is the **Full Usage** sample in `com.onesignal.unity.core/Samples~`.
The demo uses the bundle ID `com.onesignal.example` on Android and iOS, with Apple team `99SW8E36CT`. E2E builds pass `-demoBundleId com.onesignal.sdkdemo -demoTeamId DL8TF3X4K3` to `BuildScript`, which applies them for that build only. It is for repository development and testing. The user-facing sample is the **Full Usage** sample in `com.onesignal.unity.core/Samples~`.

## Prerequisites

Expand All @@ -28,20 +28,20 @@ E2E_MODE=false
ONESIGNAL_ANDROID_CHANNEL_ID=
```

- `ONESIGNAL_APP_ID`: required. The build fails without it.
- `ONESIGNAL_APP_ID`: optional. Without it (or without `.env`), the demo uses the shared example app `1154c350-e715-4b71-a58b-1b84b6745baa`.
- `ONESIGNAL_API_KEY`: REST API key, used to update and end live activities. Sending notifications from the demo doesn't need it.
- `E2E_MODE`: leave `false`. CI sets it for the Appium E2E tests.
- `ONESIGNAL_ANDROID_CHANNEL_ID`: optional Android notification channel for the sound test notification. Falls back to a built-in default channel.

Play mode in the Editor reads `.env` from this directory, and each build copies it into `Assets/StreamingAssets` (gitignored). Without `ONESIGNAL_API_KEY`, live activity update/end is disabled. Rebuild after changing `.env`.

The OneSignal app needs FCM (Android) and APNs (iOS) credentials for `com.onesignal.sdkdemo`.
The OneSignal app needs FCM (Android) and APNs (iOS) credentials for `com.onesignal.example`.

### Firebase Installation IDs (optional)

Firebase Installation IDs are off by default. To turn them on:

1. Add a Firebase Android app for `com.onesignal.sdkdemo` and save its `google-services.json` in this directory. The file is gitignored.
1. Add a Firebase Android app for `com.onesignal.example` and save its `google-services.json` in this directory. The file is gitignored.
2. Add `-define:FIREBASE_INSTALLATION_ID_ENABLED` to `Assets/csc.rsp`.

When `google-services.json` exists, the Android build applies the Google Services plugin. With the define set and no `google-services.json`, the Android build fails.
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/run-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ if [ "$INSTALL" = true ] && [ -n "$EMULATOR" ]; then
"$ADB" -s "$EMULATOR" wait-for-device
echo "Installing on $EMULATOR..."
"$ADB" -s "$EMULATOR" install -r "$OUTPUT"
"$ADB" -s "$EMULATOR" shell am start -n com.onesignal.sdkdemo/com.unity3d.player.UnityPlayerActivity
"$ADB" -s "$EMULATOR" shell am start -n com.onesignal.example/com.unity3d.player.UnityPlayerActivity
fi
2 changes: 1 addition & 1 deletion examples/demo/run-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ XCODE_DIR="$SCRIPT_DIR/Build/iOS"
LOG="$SCRIPT_DIR/Build/build-ios.log"
SCHEME="Unity-iPhone"
DERIVED="$SCRIPT_DIR/Build/iOS-DerivedData"
APP_BUNDLE_ID="com.onesignal.sdkdemo"
APP_BUNDLE_ID="com.onesignal.example"
INSTALL=true
SKIP_BUILD=false
OPEN_XCODE=false
Expand Down