skip to Main Content

hello everyone i have error in my android/java project

E/AndroidRuntime: FATAL EXCEPTION: main

Caused by: The Facebook sdk must be initialized before calling activateApp

screenshots:

image 1

image 2

4

Answers


  1. Chosen as BEST ANSWER

    slove it by update gradle and add facebook client token in manifests

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

  2. You didn’t add any code explaining the problem but after searching for this problem I found that you should add SDK initializes method in youronCreate() like the following

        @Override
        public void onCreate() {
            super.onCreate();
            FacebookSdk.sdkInitialize(getApplicationContext());
            AppEventsLogger.activateApp(this);
        }
    
    Login or Signup to reply.
  3. To use Facebook Ads Sdk in your app, You must make an App class for your app and initialize the sdk there.

    import android.app.Application;
    
    public class App extends Application {
    
        @Override
        public void onCreate() {
            super.onCreate();
            FacebookSdk.sdkInitialize(getApplicationContext());
            AppEventsLogger.activateApp(this);
        }
    }
    

    And set it in your manifest.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">
    
        <application
            android:name=".App"  <!-- Name of your app class -->
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            ........
            ........
    
        </application>
    </manifest>
    
    Login or Signup to reply.
  4. I solved the issue with RAGIP MULLAMUSA’s answer (Sorry I don’t have enough reputation to vote or comment)

    While I tried to upgrade the Facebook SDK from 9.x.x to latest (15.1.0), I found this error:

    The Facebook sdk must be initialized before calling activateApp

    I tried to put FacebookSdk.sdkInitialize(getApplicationContext()); before AppEventsLogger.activateApp(this);, and it doesn’t work. But the error will become:

    A valid Facebook app client token must be set in the AndroidManifest.xml or set by calling FacebookSdk.setClientToken before initializing the sdk.

    You might obtain the client token from https://developers.facebook.com/, and put it in AndroidManifest.xml

    <manifest
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools">
    
      <application
        android:name=".App"
        ...
        ...>
      
        <meta-data
          android:name="com.facebook.sdk.ClientToken"
          android:value="YOUR_FACEBOOK_CLIENT_TOKEN" />
      </application>
    </manifest>
    

    Note: You don’t need to keep FacebookSdk.sdkInitialize(getApplicationContext()); after putting client token in manifest.

    I tried to put FacebookSdk.setClientToken(YOUR_FACEBOOK_CLIENT_TOKEN); before super.onCreate();, but it doesn’t work for me.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search