Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
899a9fe
style: format two test files with dart format
DennisAlund Nov 17, 2026
42e8174
chore: stop tracking IDE project files
DennisAlund Nov 17, 2026
04510a6
docs: drop Facebook Analytics from the package descriptions
DennisAlund Nov 17, 2026
a27230d
test: guard the values a release must keep in step
DennisAlund Nov 17, 2026
fba03e8
ci: check formatting and analysis, test on the Flutter floor, cancel …
DennisAlund Nov 17, 2026
d993e45
fix(native): same currency and push payload handling on both platforms
DennisAlund Nov 17, 2026
9da51e8
docs: currency codes and push payloads behave the same on both platforms
DennisAlund Nov 17, 2026
209a1c5
ci: do not fail analysis on info-level findings
DennisAlund Nov 17, 2026
c766642
Merge branch 'ci/quality-gates' into fix/platform-parity
DennisAlund Nov 17, 2026
8ab00b2
ci: build the iOS example on Xcode 26.4, and probe 26.3
DennisAlund Nov 17, 2026
66c0360
test(example): integration tests against the real native SDKs
DennisAlund Nov 17, 2026
08fafaa
fix(native): accept fb_push_payload as a JSON string or a map on both…
DennisAlund Nov 17, 2026
ec96a9b
docs: fb_push_payload may be a JSON string or a map
DennisAlund Nov 17, 2026
cbc22eb
Merge branch 'fix/platform-parity' into test/native-integration
DennisAlund Nov 17, 2026
9c20b30
ci: run the integration tests on an Android emulator and an iOS simul…
DennisAlund Nov 17, 2026
64ce4ed
ci: remove the Xcode 26.3 probe
DennisAlund Nov 17, 2026
1e92d4f
docs: document the Xcode 26.4 minimum and its build errors
DennisAlund Nov 17, 2026
cad4147
Merge branch 'ci/minimum-xcode' into test/native-integration
DennisAlund Nov 17, 2026
c7a03c0
chore: actually remove the IDE project files from tracking
DennisAlund Nov 17, 2026
8cf2ac2
Merge branch 'ci/quality-gates' into test/native-integration
DennisAlund Nov 17, 2026
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
92 changes: 88 additions & 4 deletions .github/workflows/build-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,22 @@ on:

jobs:
test:
name: Dart tests
name: Dart checks — ${{ matrix.label }}
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
# The minimum Flutter the plugin supports, so the Dart layer and its tests are known
# to work there and not only on the newest SDK.
- label: "Flutter 3.41 (floor)"
flutter: "3.41.0"
- label: "Flutter stable"
flutter: ""
format: true
env:
CI: true
steps:
Expand All @@ -26,6 +37,8 @@ jobs:
uses: subosito/flutter-action@v2
with:
channel: stable
# Empty string → latest of the channel; otherwise pin to the floor version.
flutter-version: ${{ matrix.flutter }}
# The Flutter SDK is deliberately not cached (`cache: true`): each copy is 1.6-2 GB,
# which filled the repo's 10 GB Actions cache quota, and a fresh download takes about
# as long as restoring it.
Expand All @@ -35,13 +48,25 @@ jobs:
- name: Flutter pub get (root)
run: flutter pub get

- name: Flutter test (root)
run: flutter test

- name: Flutter pub get (example)
working-directory: example
run: flutter pub get

# One formatter version only: output can differ between Dart releases, and stable is
# what contributors run.
- name: Check formatting
if: ${{ matrix.format }}
run: dart format --output=none --set-exit-if-changed .

# Covers the package and the example (both resolved above). Warnings and errors fail the
# job; infos do not, because they include deprecations that differ per Flutter version
# (3.50 deprecates `package:flutter/material.dart`, whose replacement the floor lacks).
- name: Analyze
run: flutter analyze --no-fatal-infos

- name: Flutter test (root)
run: flutter test

- name: Flutter test (example)
working-directory: example
run: flutter test
Expand All @@ -68,6 +93,8 @@ jobs:
# `android.builtInKotlin=false`, so the Flutter Gradle Plugin applies KGP to the plugin.
- label: "Flutter stable"
flutter: ""
# Also runs example/integration_test on an emulator, against the real Facebook SDK.
integration: true
# AGP 9 defaults (no `android.builtInKotlin`/`android.newDsl` overrides), as in an app
# migrated to Built-in Kotlin: AGP supplies Kotlin to the plugin.
- label: "Flutter stable + Built-in Kotlin"
Expand Down Expand Up @@ -165,6 +192,32 @@ jobs:
working-directory: example
run: flutter build apk --debug -v

# The unit tests mock the method channel, so the Kotlin handlers only execute here.
- name: Enable KVM for the emulator
if: ${{ matrix.integration }}
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

# The action runs each `script` line as its own shell command. The second half removes the
# client token from the manifest, which makes the Facebook SDK fail to start (the
# situation in issue #516), and runs the tests for that case on the rebuilt app.
- name: Integration tests on an Android emulator
if: ${{ matrix.integration }}
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 34
arch: x86_64
target: google_apis
disable-animations: true
working-directory: example
script: |
flutter test integration_test/plugin_test.dart -d emulator-5554
sed -i '/com.facebook.sdk.ClientToken/,+1d' android/app/src/main/AndroidManifest.xml
if grep -q 'ClientToken' android/app/src/main/AndroidManifest.xml; then echo "client token still in the manifest"; exit 1; fi
flutter test integration_test/sdk_start_failure_test.dart -d emulator-5554

ios:
name: iOS example
needs: [test]
Expand Down Expand Up @@ -257,6 +310,16 @@ jobs:
flutter: "3.41.0"
- label: "Flutter stable"
flutter: ""
# Also runs example/integration_test on a simulator, against the real Facebook SDK.
integration: true
# The Facebook iOS SDK v19 ships Swift interfaces that only Swift 6.3+ can read, so
# the plugin needs Xcode 26.4 or newer (26.3 fails with "Consecutive statements on a
# line must be separated by ';'" in the SDK's .swiftinterface files; confirmed by a
# probe run in #524). The other cells use the runner's newest Xcode; this one keeps
# the documented minimum building.
- label: "Flutter stable, Xcode 26.4 (minimum)"
flutter: ""
xcode: "26.4"
env:
CI: true
defaults:
Expand All @@ -272,6 +335,12 @@ jobs:
with:
path: facebook_app_events

- name: Select Xcode ${{ matrix.xcode }}
if: ${{ matrix.xcode }}
run: |
sudo xcode-select -s "/Applications/Xcode_${{ matrix.xcode }}.app"
xcodebuild -version

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
Expand Down Expand Up @@ -305,6 +374,21 @@ jobs:
test -f ios/Flutter/ephemeral/Packages/.packages/FlutterFramework/Package.swift
grep -q 'FlutterGeneratedPluginSwiftPackage' ios/Runner.xcodeproj/project.pbxproj

# The unit tests mock the method channel, so the Swift handlers only execute here.
- name: Integration tests on an iOS simulator
if: ${{ matrix.integration }}
working-directory: facebook_app_events/example
run: |
set -euo pipefail
udid="$(xcrun simctl list devices available --json \
| jq -r '[.devices[][] | select(.name | startswith("iPhone"))] | last | .udid // empty')"
if [ -z "$udid" ]; then
echo "::error::No available iPhone simulator on this runner"
exit 1
fi
xcrun simctl boot "$udid"
flutter test integration_test/plugin_test.dart -d "$udid"

# Flutter only prints this warning (it does not fail the build), so check for it explicitly.
# Runs even if an earlier step failed, so the specific error still shows up in that case.
# test/ios_package_swift_test.dart is the primary guard; this catches Flutter-side changes.
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ jobs:

- run: flutter --version

# The tag is what triggers publishing, but pub.dev publishes the version in pubspec.yaml.
# Stop here if the two disagree. (pubspec, podspec and CHANGELOG are kept in step by
# test/release_consistency_test.dart, which the verify job has already run.)
- name: Check that the tag matches pubspec.yaml
env:
TAG_NAME: ${{ github.ref_name }}
run: |
set -euo pipefail
pubspec_version="$(sed -nE 's/^version:[[:space:]]*([^[:space:]]+).*/\1/p' pubspec.yaml)"
if [ "v${pubspec_version}" != "$TAG_NAME" ]; then
echo "::error::Tag ${TAG_NAME} does not match pubspec.yaml version ${pubspec_version}"
exit 1
fi

- run: flutter pub get

- name: Publish package
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/main_verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ on:
branches:
- main

# Never cancel a run on main half way: it is the one that saves the shared caches. Runs for
# later pushes wait their turn.
concurrency:
group: main-verify
cancel-in-progress: false

jobs:
build-verify:
uses: ./.github/workflows/build-verify.yml
6 changes: 6 additions & 0 deletions .github/workflows/pr_acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ name: PR acceptance
on:
pull_request:

# A new push to a pull request makes the runs for its older commits pointless. Cancel them so
# they stop holding runners (the macOS queue in particular).
concurrency:
group: pr-acceptance-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
# Build confirmation lives in the reusable build-verify workflow so it stays in sync with the
# release pipeline (build_deploy.yml) — same Android matrix + iOS build for both.
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.DS_Store

# IDE project files: machine-specific, and anything tracked here is also published to pub.dev
.idea/
*.iml
.dart_tool/

.packages
Expand Down
3 changes: 0 additions & 3 deletions .idea/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions .idea/flutter_facebook_app_events.iml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/libraries/Flutter_Plugins.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Guidance for AI coding agents (Claude Code, Codex and others) working in this re

Read [`CONTRIBUTING.md`](CONTRIBUTING.md) and follow the guidelines in it. In particular, the **Release Process** section lists files that must stay in sync (e.g. `pubspec.yaml` and `ios/facebook_app_events.podspec` versions) — consult it before preparing a release or bumping the version.

CI (`.github/workflows/build-verify.yml`) fails on unformatted Dart (`dart format`), analyzer findings (`flutter analyze`) and failing tests, on both the Flutter floor and stable. `test/release_consistency_test.dart` checks the values the Release Process says must match.

`example/integration_test/` runs the plugin inside the example app against the real Facebook SDK, on an Android emulator and an iOS simulator in CI. It is the only place the Kotlin and Swift handlers execute (the tests in `test/` mock the method channel), so a change to native behavior should come with a test there. Tests in that folder share one app process and run in file order.

## Plugin architecture

This plugin exposes Meta's Facebook App Events SDK to Flutter with an explicit 1:1 mapping between the Dart API and the native handlers. When adding, renaming, or modifying a method, keep the three layers in sync:
Expand All @@ -32,4 +36,6 @@ The plugin follows the **major** version of the Facebook SDK (currently v19.x).
- Deferred SDK initialization (`FacebookAutoInitEnabled` on iOS, `com.facebook.sdk.AutoInitEnabled` on Android, `initializeSdk()` in Dart): on iOS the SDK is fully unconfigured until `initializeSdk()`, so the Swift handler gates every method call except `initializeSdk`/`setGraphApiVersion` (and the URL forwarders) behind a `isSdkInitialized` flag and returns `FlutterError(sdk_not_initialized)`; adding a new handler must keep it behind that gate unless its SDK call is verified safe pre-configuration. On Android `AutoInitEnabled=false` still runs `sdkInitialize`, so there is no deferred-init gate and `initializeSdk` maps to `FacebookSdk.fullyInitialize()` — never `setAutoInitEnabled(true)`, which persists and overrides the manifest. If the Android SDK is not initialized at all (`FacebookInitProvider` swallows a failed start, or the app removed the provider), `onMethodCall` converts the SDK's `FacebookSdkNotInitializedException` to the same `sdk_not_initialized` code, and `initializeSdk` is the only place the plugin calls `sdkInitialize` (failing with `sdk_initialization_failed`); never initialize implicitly, since the app may be holding the SDK back for consent. For the same reason nothing in `onAttachedToEngine` may throw, and the `AppEventsLogger` is created lazily.
- `setUserData` uses merge semantics on both platforms: only fields present in the call are updated. The iOS handler deliberately skips absent keys because passing nil to the native setter would *clear* the field on iOS (Android ignores nulls).
- Graph API version override: plugin forces `v24.0` at init on both platforms. The Android SDK still defaults to the removed `v16.0` in v19.0.0 (`ServerProtocol.getDefaultAPIVersion`); the iOS SDK has defaulted to `v26.0` since 18.1.1, but the pin is kept on both for consistent Graph behavior. Revisit when the Android SDK ships a corrected default.
- Currency codes (`logPurchase`, `logProductItem`) are validated natively on both platforms, case-insensitively, and an unknown code returns `INVALID_ARGUMENT`. Android has to (the SDK takes a `java.util.Currency`); the iOS handler does the same check itself because the iOS SDK accepts any string.
- `logPushNotificationOpen` payloads are passed through leniently: the Android handler drops values a `Bundle` cannot hold instead of failing, because the SDK only reads `fb_push_payload` and iOS accepts any payload. Both handlers also convert `fb_push_payload` to the shape their SDK needs (JSON string on Android, dictionary with a string `campaign` on iOS); the iOS SDK crashes on anything else, so that normalization must stay.
- Event parameters are validated in the Dart layer (`String`/`num`/`bool` only, bool sent as `"1"`/`"0"`) because the native SDKs silently drop events with other value types.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ After that, add that string resource reference to your main `AndroidManifest.xml

### Configure iOS

Building requires **Xcode 26.4 or newer** (see [the build errors older versions give](#ios-build-fails-in-the-facebook-sdks-swiftinterface-files)).

This plugin requires **iOS 15.0 or newer**, the minimum of the Facebook iOS SDK v19. If your app targets an older version, raise `IPHONEOS_DEPLOYMENT_TARGET` to `15.0` in `ios/Runner.xcodeproj` (Runner target → General → Minimum Deployments) and, if your `ios/Podfile` has an uncommented `platform :ios, ...` line, set it to `'15.0'` as well. Otherwise CocoaPods or Swift Package Manager will refuse to resolve the Facebook SDK.

**Upgrading from a plugin version built on Facebook SDK 18.x (0.31.x or older) with CocoaPods:** your app's `ios/Podfile.lock` still pins `FBSDKCoreKit` 18.x, and `pod install` does not move a plugin's transitive dependency when the plugin's constraint changes. The build stops with "changed the constraints of dependency `FBSDKCoreKit` inside your development pod `facebook_app_events`", and the `pod repo update` hint Flutter prints does not fix it. After upgrading, run this once:
Expand Down Expand Up @@ -247,6 +249,20 @@ Compare `errorCode`, not `code`: `code` is the wire string from the table, not t

Full diagnosis, split by layer (configuration, transport, attribution), with per-platform verification steps: [events not showing in Events Manager](https://oddb.it/fbae-guide-not-landing).

### iOS build fails in the Facebook SDK's `.swiftinterface` files

With plugin 0.32.0 or newer, an iOS build on an Xcode older than 26.4 stops with errors like these, pointing into the Facebook SDK's frameworks (`FBSDKCoreKit`, `FBAEMKit` and others):

```
.../FBAEMKit.framework/Modules/FBAEMKit.swiftmodule/arm64-apple-ios.private.swiftinterface:13:63: error: Expected type
.../arm64-apple-ios.private.swiftinterface:13:81: error: Consecutive statements on a line must be separated by ';'
```

The Facebook iOS SDK v19 ships its Swift interfaces in a syntax that needs Swift 6.3, which comes with Xcode 26.4. It affects device and simulator builds alike, on every architecture, with both CocoaPods and Swift Package Manager. Check your version with `xcodebuild -version`, then either:

1. **Update Xcode to 26.4 or newer.** This is the fix if you can.
2. **Stay on the last plugin release that uses Facebook SDK v18:** set `facebook_app_events: ^0.31.1` in `pubspec.yaml`. With CocoaPods, also run `cd ios && pod update FBSDKCoreKit`, because `Podfile.lock` still pins v19.

### `sdk_not_initialized` on Android

On Android the Facebook SDK initializes itself when the app process starts. If that fails, the SDK only writes an info-level `Failed to auto initialize the Facebook SDK` line to logcat and the app keeps running. Plugin calls that need the SDK, such as `logEvent`, then fail with a `FacebookAppEventsException` whose `errorCode` is `sdkNotInitialized` (wire code `sdk_not_initialized`). Before this was handled, the same situation surfaced as `lateinit property appEventsLogger has not been initialized`.
Expand Down
3 changes: 0 additions & 3 deletions android/.idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion android/.idea/.name

This file was deleted.

6 changes: 0 additions & 6 deletions android/.idea/compiler.xml

This file was deleted.

19 changes: 0 additions & 19 deletions android/.idea/gradle.xml

This file was deleted.

25 changes: 0 additions & 25 deletions android/.idea/jarRepositories.xml

This file was deleted.

6 changes: 0 additions & 6 deletions android/.idea/kotlinc.xml

This file was deleted.

9 changes: 0 additions & 9 deletions android/.idea/misc.xml

This file was deleted.

Loading
Loading