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
4 changes: 4 additions & 0 deletions .github/actions/create-demo-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ runs:
working-directory: examples/demo
shell: bash
run: |
if [ -z "${{ inputs.onesignal-app-id }}" ]; then
echo "::error::onesignal-app-id is empty; the demo app throws at startup without it"
exit 1
fi
{
echo "ONESIGNAL_APP_ID=${{ inputs.onesignal-app-id }}"
echo "ONESIGNAL_API_KEY=${{ inputs.onesignal-api-key }}"
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ jobs:
onesignal-app-id: ${{ vars.APPIUM_ONESIGNAL_APP_ID }}
onesignal-api-key: ${{ secrets.APPIUM_ONESIGNAL_API_KEY }}

- name: Write demo google-services.json
uses: OneSignal/sdk-shared/.github/actions/setup-google-services@main
with:
google-services-json: ${{ secrets.APPIUM_GOOGLE_SERVICES_JSON }}
path: examples/demo/android/app/google-services.json

- name: Build release APK
working-directory: examples/demo
run: flutter build apk --release
run: flutter build apk --release -PFIREBASE_INSTALLATION_ID_ENABLED=true

- name: Upload APK
uses: actions/upload-artifact@v7
Expand Down Expand Up @@ -138,6 +144,7 @@ jobs:
platform: android
app-artifact: demo-apk
app-filename: app-release.apk
bundle-id: com.onesignal.sdkdemo
sdk-type: flutter
build-name: flutter-android-${{ github.ref_name }}-${{ github.run_number }}

Expand Down
4 changes: 2 additions & 2 deletions examples/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ flutter_launcher_icons:
### Environment variables

- `flutter_dotenv` loads `.env` from the `pubspec.yaml` `assets:` block (`.env` is listed alongside `assets/onesignal_logo.svg`).
- `ONESIGNAL_APP_ID` -- OneSignal app id. Falls back to the hard-coded `_defaultAppId` in `main.dart` when unset or empty.
- `ONESIGNAL_APP_ID` -- OneSignal app id. Required; `main.dart` throws a `StateError` when unset or empty.
- `ONESIGNAL_API_KEY` -- REST API key used by `OneSignalApiService` for Live Activity update/end and notification sends.
- `ONESIGNAL_ANDROID_CHANNEL_ID` -- optional Android notification channel id used by the REST send paths.

Expand Down Expand Up @@ -125,7 +125,7 @@ OneSignal.Location.setShared(prefs.locationShared);
- IAM: `addWillDisplayListener`, `addDidDisplayListener`, `addWillDismissListener`, `addDidDismissListener`, `addClickListener`
- Notifications: `addClickListener`, `addForegroundWillDisplayListener` (calls `event.notification.display()`)
- `TooltipHelper().init()` fetches tooltip content in the background.
- `appId` falls back to a hard-coded `_defaultAppId` constant when `ONESIGNAL_APP_ID` is not set in `.env`.
- `appId` comes from `ONESIGNAL_APP_ID` in `.env`; there is no default.

`PreferencesService` is the source of truth for restored UI state. In `AppViewModel.loadInitialState(appId)`, read UI state from `_prefs` (not from the SDK):
```dart
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-no-location-pods/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

android {
namespace = "com.onesignal.example"
namespace = "com.onesignal.sdkdemo"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

Expand All @@ -15,7 +15,7 @@ android {
}

defaultConfig {
applicationId = "com.onesignal.example"
applicationId = "com.onesignal.sdkdemo"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.onesignal.example
package com.onesignal.sdkdemo

import io.flutter.embedding.android.FlutterActivity

Expand Down
4 changes: 2 additions & 2 deletions examples/demo-no-location/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

android {
namespace = "com.onesignal.example"
namespace = "com.onesignal.sdkdemo"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

Expand All @@ -15,7 +15,7 @@ android {
}

defaultConfig {
applicationId = "com.onesignal.example"
applicationId = "com.onesignal.sdkdemo"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.onesignal.example
package com.onesignal.sdkdemo

import io.flutter.embedding.android.FlutterActivity

Expand Down
2 changes: 1 addition & 1 deletion examples/demo-pods/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ONESIGNAL_APP_ID=your-onesignal-app-id # default app id: 77e32082-ea27-42e3-a898-c72e141824ef if empty
ONESIGNAL_APP_ID=your-onesignal-app-id
ONESIGNAL_API_KEY=your-onesignal-api-key

# Optional: Android Notification Channel ID for the WITH SOUND test notification.
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-pods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ONESIGNAL_APP_ID=your-onesignal-app-id
ONESIGNAL_API_KEY=your-onesignal-api-key
```

The `.env` file must exist before the first build because Flutter bundles it as an app asset. If `ONESIGNAL_APP_ID` is empty, the app falls back to a built-in default App ID.
The `.env` file must exist before the first build because Flutter bundles it as an app asset. The app throws at startup when `ONESIGNAL_APP_ID` is empty.

## Build Guide

Expand Down
4 changes: 2 additions & 2 deletions examples/demo-pods/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

android {
namespace = "com.onesignal.example"
namespace = "com.onesignal.sdkdemo"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

Expand All @@ -16,7 +16,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.onesignal.example"
applicationId = "com.onesignal.sdkdemo"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.onesignal.example
package com.onesignal.sdkdemo

import io.flutter.embedding.android.FlutterActivity

Expand Down
11 changes: 7 additions & 4 deletions examples/demo-pods/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ import 'services/tooltip_helper.dart';
import 'theme.dart';
import 'viewmodels/app_viewmodel.dart';

const String _defaultAppId = '77e32082-ea27-42e3-a898-c72e141824ef';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

try {
await dotenv.load(fileName: '.env');
} catch (_) {
debugPrint('.env file not found, using defaults');
debugPrint('.env file not found');
}

final prefs = PreferencesService();
await prefs.init();

final envAppId = dotenv.env['ONESIGNAL_APP_ID'];
final appId = (envAppId != null && envAppId.isNotEmpty) ? envAppId : _defaultAppId;
final appId = envAppId?.trim() ?? '';
if (appId.isEmpty) {
throw StateError(
'ONESIGNAL_APP_ID is not set. Add it to examples/demo-pods/.env.',
);
}

// Initialize OneSignal SDK
OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
Expand Down
14 changes: 12 additions & 2 deletions examples/demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,28 @@ ONESIGNAL_API_KEY=your-onesignal-api-key
ONESIGNAL_ANDROID_CHANNEL_ID=
```

- `ONESIGNAL_APP_ID`: falls back to a built-in default App ID when empty.
- `ONESIGNAL_APP_ID`: required. The app throws at startup when it is empty.
- `ONESIGNAL_API_KEY`: REST API key, used to update and end live activities. Sending notifications from the demo doesn't need it.
- `ONESIGNAL_ANDROID_CHANNEL_ID`: optional Android notification channel for the sound test notification. Falls back to a built-in default channel.

The OneSignal app needs FCM credentials for Android and APNs credentials for the `com.onesignal.example` bundle ID on iOS.
The OneSignal app needs FCM credentials for the `com.onesignal.sdkdemo` Android package and APNs credentials for the `com.onesignal.example` bundle ID on iOS.

Then fetch dependencies:

```bash
flutter pub get
```

### Firebase Installation IDs (optional)
Comment thread
fadi-george marked this conversation as resolved.
Resolved

E2E builds register with Firebase Installation IDs. To match locally, put a `google-services.json` for `com.onesignal.sdkdemo` in `android/app/` (it is gitignored) and build with:

```bash
flutter build apk -PFIREBASE_INSTALLATION_ID_ENABLED=true
```

The flag is off by default, and the build fails if it is on without `google-services.json`.

## Run

```bash
Expand Down
1 change: 1 addition & 0 deletions examples/demo/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ GeneratedPluginRegistrant.java
key.properties
**/*.keystore
**/*.jks
app/google-services.json
25 changes: 22 additions & 3 deletions examples/demo/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ plugins {
id("dev.flutter.flutter-gradle-plugin")
}

val hasGoogleServices = file("google-services.json").exists()

// E2E builds pass `-PFIREBASE_INSTALLATION_ID_ENABLED=true` (`flutter build apk -P...`).
// The flag does nothing without the default FirebaseApp from google-services.json.
val firebaseInstallationIdEnabled =
(findProperty("FIREBASE_INSTALLATION_ID_ENABLED") as? String)?.trim()?.toBoolean() ?: false
if (firebaseInstallationIdEnabled && !hasGoogleServices) {
throw GradleException("FIREBASE_INSTALLATION_ID_ENABLED requires examples/demo/android/app/google-services.json")
}

android {
namespace = "com.onesignal.example"
namespace = "com.onesignal.sdkdemo"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

Expand All @@ -15,14 +25,14 @@ android {
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.onesignal.example"
applicationId = "com.onesignal.sdkdemo"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
manifestPlaceholders["firebaseInstallationIdEnabled"] = firebaseInstallationIdEnabled.toString()
}

buildTypes {
Expand All @@ -43,3 +53,12 @@ kotlin {
flutter {
source = "../.."
}

dependencies {
// OneSignal resolves firebase-messaging 24.x; Installation ID registration needs 25.1.2+.
implementation("com.google.firebase:firebase-messaging:25.1.3")
}

if (hasGoogleServices) {
apply(plugin = "com.google.gms.google-services")
}
3 changes: 3 additions & 0 deletions examples/demo/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
android:label="OneSignal Demo"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<meta-data
android:name="firebase_messaging_installation_id_enabled"
android:value="${firebaseInstallationIdEnabled}" />
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.onesignal.example
package com.onesignal.sdkdemo

import io.flutter.embedding.android.FlutterActivity

Expand Down
1 change: 1 addition & 0 deletions examples/demo/android/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "9.1.0" apply false
id("org.jetbrains.kotlin.android") version "2.4.0" apply false
id("com.google.gms.google-services") version "4.4.4" apply false
}

include(":app")
12 changes: 7 additions & 5 deletions examples/demo/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@ import 'services/tooltip_helper.dart';
import 'theme.dart';
import 'viewmodels/app_viewmodel.dart';

const String _defaultAppId = '77e32082-ea27-42e3-a898-c72e141824ef';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

try {
await dotenv.load(fileName: '.env');
} catch (_) {
debugPrint('.env file not found, using defaults');
debugPrint('.env file not found');
}

final prefs = PreferencesService();
await prefs.init();

final envAppId = dotenv.env['ONESIGNAL_APP_ID'];
final appId =
(envAppId != null && envAppId.isNotEmpty) ? envAppId : _defaultAppId;
final appId = envAppId?.trim() ?? '';
if (appId.isEmpty) {
throw StateError(
'ONESIGNAL_APP_ID is not set. Add it to examples/demo/.env.',
);
}

// Initialize OneSignal SDK
OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
Expand Down
4 changes: 2 additions & 2 deletions examples/flutter-local-notif/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ for notifications created by the app. Its layout and test flow mirror the
## Setup

1. Create or select an app in the [OneSignal dashboard](https://dashboard.onesignal.com/).
2. Configure its Android and iOS platforms using bundle ID
`com.onesignal.example`.
2. Configure its Android platform with package `com.onesignal.sdkdemo` and its
iOS platform with bundle ID `com.onesignal.example`.
3. On iOS, select the `Runner` target in Xcode and choose your development team.
The Push Notifications entitlement and remote notification background mode
are already present. Add a OneSignal Notification Service Extension if you
Expand Down
4 changes: 2 additions & 2 deletions examples/flutter-local-notif/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

android {
namespace = "com.onesignal.example"
namespace = "com.onesignal.sdkdemo"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

Expand All @@ -16,7 +16,7 @@ android {
}

defaultConfig {
applicationId = "com.onesignal.example"
applicationId = "com.onesignal.sdkdemo"
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.onesignal.sdkdemo

import io.flutter.embedding.android.FlutterActivity

class MainActivity : FlutterActivity()
Loading