Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deprecated FacebookSdk method throws RuntimeException

I have FacebookSdk.sdkInitialize(getApplicationContext()) where sdkInitialize() is displayed as deprecated. According to this article we can just delete that line. But then I get 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?

like image 303
Ralf Wickum Avatar asked Dec 13 '22 22:12

Ralf Wickum


2 Answers

No need of AppEventsLogger.activateApp(this); now it is not required if you have set up facebook_id in manifest.xml u just have to add 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

like image 81
Anuj Jindal Avatar answered Feb 04 '23 11:02

Anuj Jindal


That is because you upgraded your Facebook SDK and you are trying to use implemention of AppEventsLogger providinig this as Context:

AppEventsLogger.activateApp(this);

and that is replaced from SDK 4.19 and above with:

AppEventsLogger.activateApp(getApplication());

Documentation about this says:

Notifies the events system that the app has launched and activate and deactivate events should start being logged automatically. This should be called from the OnCreate method of you application.

That have logic if Facebook SDK now is auto initialized on Application start.

Try that I hope this will solve your problem.

like image 28
Yupi Avatar answered Feb 04 '23 10:02

Yupi