Flutter facebook app events : lateinit property anonymousId has not been initialized

1.2k Views Asked by At

I'm trying to call Facebook app events in my flutter project. I'm using the dependency facebook_app_events: ^0.12.0. meta-data is also added in the manifest file.

    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />


void callFBEvent() async {
    try {
      var i = await facebookAppEvents.getAnonymousId();
      await facebookAppEvents.setAdvertiserTracking(enabled: true);
      await facebookAppEvents.logEvent(
          name: "User_Selection_Screen", parameters: {
        "User_Selection": "User_Selection",
      });
      print("facebook event success User_Selection_Screen");
    }catch(e){
      print(e);
    }
  }

Getting below error

kotlin.UninitializedPropertyAccessException: lateinit property anonymousId has not been initialized
    at id.oddbit.flutter.facebook_app_events.FacebookAppEventsPlugin.handleGetAnonymousId(FacebookAppEventsPlugin.kt:82)
    at id.oddbit.flutter.facebook_app_events.FacebookAppEventsPlugin.onMethodCall(FacebookAppEventsPlugin.kt:55)
    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:822)
    at android.os.MessageQueue.nativePollOnce(Native Method)
    at android.os.MessageQueue.next(MessageQueue.java:336)
    at android.os.Looper.loop(Looper.java:174)
    at android.app.ActivityThread.main(ActivityThread.java:7386)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
3

There are 3 best solutions below

0
On BEST ANSWER

I open the project in an android module. Then just clean the build of the project first and then just build and sync the Gradle in the android module. then the issue was solved. But I already use pub get lots of time before that but that didn't work. fine, my issue was solved.

0
On

In my case the problem was that I inserted the the meta data under actvity tag instead of inserting that under application tag

        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
0
On

So the solution was basically to put the :

<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken"
android:value="@string/facebook_client_token"/>

in the right spot , they need to be under the application Tag , in the first range so not under appliction and then activity tag just under the application tag in the androidManifest just as in the pic below ! enter image description here