'Flutter Facebook App Events gives the error: kotlin.UninitializedPropertyAccessException: lateinit property appEventsLogger has not been initialized
I am using the latest version of FaceBook App Events plugin in Flutter with the latest version of Flutter as well. On click event, I am calling the logEvent method like this:
facebookAppEvents.logEvent(
name: 'Link Clicked',
parameters: {'url': request.url},
);
where the facebookAppEvents defined and initialized in the class itself:
static final facebookAppEvents = FacebookAppEvents();
Advertiser tracking is working with no problem using the following statement:
facebookAppEvents.setAdvertiserTracking(enabled: true);
However, I am getting an exception when calling the logEvent method. The exception is:
E/MethodChannel#flutter.oddbit.id/facebook_app_events(26467): Failed to handle method call
E/MethodChannel#flutter.oddbit.id/facebook_app_events(26467): kotlin.UninitializedPropertyAccessException: lateinit property appEventsLogger has not been initialized
Flutter doctor has no problem nor warning. I tried to clean and rebuild the project but still getting the same exception. All the tests I did are on Android only. Any way to fix this?
Solution 1:[1]
This library has a bug in it's source code. If you paste the exact stack trace I might be able to pin point the bug and maybe send a patch to the library owner for review.
Their code (where "appEventsLogger" is defined): https://github.com/oddbit/flutter_facebook_app_events/blob/develop/android/src/main/kotlin/id/oddbit/flutter/facebook_app_events/FacebookAppEventsPlugin.kt
Solution 2:[2]
I added ApplicationId meta data only because the flutter plugin documentation said so and got the error. But then solved it by adding ClientToken to AndroidManifest.xml ( you should add facebook_client_token as a string resource as well )
AndroidManifest.xml
<application android:label="@string/app_name" ...>
<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"/>
</application>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="facebook_app_id">123123</string>
<string name="facebook_client_token">456456</string>
</resources>
More Info: https://developers.facebook.com/docs/app-events/getting-started-app-events-android
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Re'em |
Solution 2 | erdemlal |