Holding the Facebook SDK back until consent in a Flutter app

Last updated November 17, 2026

The flags most apps set are not enough

By default the Facebook SDK is initialized before your Dart code runs. On iOS the plugin initializes it when it registers. On Android the SDK's own FacebookInitProvider runs at process start.

Initialization is not inert. It fetches gatekeeper, server and domain configuration from Meta and writes to local storage. The AutoLogAppEventsEnabled and AdvertiserIDCollectionEnabled flags do not prevent that. They only stop app events from being logged.

If your app must not reach Meta until the user has agreed, turning off auto-logging is not the answer. You have to defer initialization itself.

Turn automatic initialization off

Set one key per platform:

<!-- ios/Runner/Info.plist -->
<key>FacebookAutoInitEnabled</key>
<false/>
<!-- android/app/src/main/AndroidManifest.xml, under <application> -->
<meta-data android:name="com.facebook.sdk.AutoInitEnabled" android:value="false"/>

Then initialize from Dart once consent exists:

final facebookAppEvents = FacebookAppEvents();

// After the user has consented, and on every later launch
// where consent is already stored.
await facebookAppEvents.initializeSdk();
await facebookAppEvents.activateApp(); // only if auto-logging is also off

The plugin does not remember the decision for you. Call initializeSdk() on every launch where consent is stored. Calling it more than once is harmless, and an absent key means automatic initialization stays on, so existing apps are not affected.

The two platforms do not behave the same

This is where consent flows break.

iOS: nothing works until you initialize

With FacebookAutoInitEnabled set to false the iOS SDK is unconfigured, and it does not tolerate calls in that state. App event methods throw in debug builds and are silently dropped in release. The persisted settings setters crash. The app id is cached as empty for the rest of the process.

So the plugin rejects every method except initializeSdk and setGraphApiVersion with the error code sdk_not_initialized. The error is deliberate. It shows up in development instead of as lost data in production.

In practice: call initializeSdk() before setUserData, setDataProcessingOptions, setLimitEventAndDataUsage, setAutoLogAppEventsEnabled or any logging call.

Android: the SDK is already awake

AutoInitEnabled=false does not keep the Android SDK asleep. The app id and client token are still loaded at process start, and plugin calls still work. The SDK is only not "fully initialized", and initializeSdk() completes that step.

A consent flow written and tested on Android can therefore be in the wrong order for iOS. Test the flow on both.

When Android reports sdk_not_initialized

On Android this error means something else: the SDK failed to start at all. It does so quietly. The only trace is an info-level Failed to auto initialize the Facebook SDK line in logcat, and the app keeps running.

Older plugin versions surfaced this as lateinit property appEventsLogger has not been initialized. From version 0.34.0 the calls that need the SDK fail with sdk_not_initialized, and initializeSdk() tells you why:

try {
  await facebookAppEvents.initializeSdk();
} on FacebookAppEventsException catch (e) {
  if (e.errorCode == FacebookAppEventsErrorCode.sdkInitializationFailed) {
    // The SDK's own reason, for example a missing client token.
    debugPrint(e.message);
  }
}

The usual reason is that the app id or the client token could not be read from AndroidManifest.xml. Where the client token goes covers the two files Android needs.

Two details matter here. The plugin never initializes the SDK by itself, so an app that holds the SDK back for consent is not overridden. And await your plugin calls inside the try block. An un-awaited call that fails becomes an unhandled error and never reaches your catch.

What Android still captures before consent

Deferring initialization does not defer everything on Android. Since Facebook SDK v19 the SDK stores the URL that opened your app, and on Android that starts at process start even with AutoInitEnabled=false. If nothing may be collected before consent, you need a second manifest key. What SDK v19 attaches to your events has the details.

Verify your setup

  • FacebookAutoInitEnabled is false in Info.plist and com.facebook.sdk.AutoInitEnabled is false in AndroidManifest.xml
  • initializeSdk() runs on every launch where consent is already stored, not only on the launch where the user agreed
  • On iOS, initializeSdk() is called before any setter or logging call
  • You tested the consent flow on iOS and on Android, not on one of them
  • Plugin calls are awaited inside the try block that is meant to catch their errors
  • If nothing may be stored before consent on Android, com.facebook.sdk.AutoLogMetaDataEnabled is false as well

Meta's reference documentation

Plugin API reference

Still stuck?

It is a plugin defect

If the plugin is doing something the native Facebook SDK does not, that is our bug. Open an issue and we fix it. Free, always, no conditions.

Open a GitHub issue

It is a usage question

Configuration and integration questions are best asked where other developers can find the answer later.

Ask on StackOverflow

Your numbers are wrong and money is moving

If Meta install campaigns are spending and the attribution does not add up, that is a different problem from a broken build. It starts with a free 20 minute call. The one hour diagnostic, 300 USD and credited against the audit, follows if it is worth it.

See the diagnostic and audit

Related guides