Deprecated FacebookSdk method throws RuntimeException

I have FacebookSdk.sdkInitialize(getApplicationContext())

where sdkInitialize () appears to be deprecated. According to this article, we can simply delete this line. But then I get the following error for the line after AppEventsLogger.activateApp(this)

:

AndroidRuntime: FATAL EXCEPTION: main                                                                              Process: com.daimler.moovel.android:auth, PID: 4011                                java.lang.RuntimeException: Unable to create application com.daimler.moovel.android.DebugApplication: The Facebook sdk must be initialized before calling activateApp                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5879)                                             at android.app.ActivityThread.-wrap3(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1699)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: The Facebook sdk must be initialized before calling activateApp
at com.facebook.appevents.AppEventsLogger.activateApp(AppEventsLogger.java:226)
at com.facebook.appevents.AppEventsLogger.activateApp(AppEventsLogger.java:208)

      

So what am I missing?

+3


source to share


2 answers


This is because you updated yours Facebook SDK

and you are trying to use AppEventsLogger

provinig implementation this

like Context

:

AppEventsLogger.activateApp(this);

and is replaced with SDK 4.19 and higher with:

AppEventsLogger.activateApp(getApplication());



The documentation says about it:

Informs that the event system that the application started and activate and deactivate events should start automatically. This needs to be called from your application's OnCreate method.

This has logic if it is Facebook SDK

now automatically initialized when the application starts.

Try it, I hope this solves your problem.

+2


source


No need AppEventsLogger.activateApp(this);

now this is not required if you have created facebook_id in manifest.xml You just need to add the following in Application tag in manifest.xml

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

      



where facebook_app_id is defined in string.xml file

+4


source







All Articles