4

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?

Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103

2 Answers2

9

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

Anuj Jindal
  • 1,711
  • 15
  • 24
3

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.

Yupi
  • 4,402
  • 3
  • 18
  • 37
  • 1
    yupi, i have already added `AppEventsLogger.activateApp(getApplication());` ,still there is crash for some user on fabric,don't know how to resolve that,crash is for some user only – Om Infowave Developers Oct 12 '17 at 04:20