Facebook SDK Android AppEventsLogger NullPointerException on flash

I have included the current FacebookSDK for Android v3.5 for tracking. You can track application installations by calling com.facebook.AppEventsLogger.activateApp (context, YOUR_APP_ID);

So far no problem, I see that these events are displayed on the facebook toolbar. When it comes to tracking events or purchase events, facebook recomments does the following:

m_fbAppEventsLogger = com.facebook.AppEventsLogger.newLogger(applicationcontext); m_fbAppEventsLogger.logPurchase(BigDecimal.valueOf(4.99), Currency.getInstance("USD")); 

Purchase events appear to be cleared immediately, resulting in

 09-22 15:10:04.680: D/com.facebook.AppEventsLogger(31691): Caught unexpected exception while flushing: java.lang.NullPointerException 

If I try to send a custom event, the same error will occur if the facebook SDK decides to drop events in the queue.

I did not find anything for this behavior, so any help would be greatly appreciated.

+6
source share
2 answers

you must add <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/> to your AndroidManifest.xml

+2
source

I initialize the Facebook SDK in different ways with the examples given in their documentation.

Facebook recommends that you define meta-data android:name="com.facebook.sdk.ApplicationId in AndroidManifest.xml and hardcode value for facebook_app_id in strings.xml . If you use a control source, these files are usually checked and usually I do not like to pass my keys to remote repositories.

I am outputting a string resource called facebook_app_id from an external file with my gradle construct. Then I define facebook_app_id manually when I initialize the SDK for Facebook, rather than relying on the library to find it.

Initialize SDK

Initialize the Facebook SDK (allows you to track installation events):

 private void initialiseFacebook(Application application) { FacebookSdk.sdkInitialize(application); AppEventsLogger.activateApp(application, application.getString(R.string.facebook_app_id)); } 

Initialize Facebook AppEventsLogger

Subsequently, I wanted to register Facebook App Events . I could see that my installation events were successfully tracked by Facebook Analytics. However, every time I tried to register an event, the following error was returned:

Caught an unexpected exception while flushing: java.lang.NullPointerException

For me, the solution was to manually define facebook_app_id again in my method call to create the AppEventsLogger. This solved the problem for me.

 AppEventsLogger.newLogger(application, application.getString(R.string.facebook_app_id)); 

Also: Enable SDK debugging:

It was very useful for me to have more detailed logs from the Facebook SDK when I was looking for this problem. You can configure it using the code below:

 FacebookSdk.setIsDebugEnabled(true); FacebookSdk.addLoggingBehavior(LoggingBehavior.REQUESTS); 

This method also has the advantage that you can use different facebook_app_id for each type of build and / or taste.

+2
source

Source: https://habr.com/ru/post/954257/


All Articles