'Failed to auto initialize the Facebook SDKFailed to auto initialize the Facebook SDK

I'm new to mobile development. And while I was developing my app, I got the following error:

Failed to auto initialize the Facebook SDK
A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.
    at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:39)
    at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:9)
    at com.facebook.internal.FacebookInitProvider.onCreate(FacebookInitProvider.java:1)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2118)
    at android.content.ContentProvider.attachInfo(ContentProvider.java:2092)
    at android.app.ActivityThread.installProvider(ActivityThread.java:7189)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6672)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6567)
    at android.app.ActivityThread.access$1400(ActivityThread.java:224)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7562)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

As long as I'm using the development app, everything works fine. But when I do the build (apk), there to work.

I found a few things regarding facebook login, but I'm trying to just use google login, so I don't know where this error is coming from.

Just followed the implementation as in the example app of @react-native-google-signin/google-signin

I'm using firebase to create a google signin, and also using the following packages:

"@react-native-firebase/app": "^13.0.1",
"@react-native-firebase/auth": "^13.1.0",
"@react-native-firebase/database": "^13.0.1",
"@react-native-google-signin/google-signin": "^7.0.1",

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hemerson.appName">
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.READ_CALENDAR"/>
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
  <uses-permission android:name="android.permission.VIBRATE"/>
  <uses-permission android:name="android.permission.WRITE_CALENDAR"/>
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  <queries>
    <intent>
      <action android:name="android.intent.action.VIEW"/>
      <category android:name="android.intent.category.BROWSABLE"/>
      <data android:scheme="https"/>
    </intent>
  </queries>
  <application 
    android:name=".MainApplication" 
    android:label="@string/app_name" 
    android:icon="@mipmap/ic_launcher" 
    android:roundIcon="@mipmap/ic_launcher_round" 
    android:allowBackup="true" 
    android:theme="@style/AppTheme" 
    android:usesCleartextTraffic="true"
    android:requestLegacyExternalStorage="true"
  >
    <meta-data android:name="expo.modules.updates.ENABLED" android:value="true"/>
    <meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="43.0.0"/>
    <meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
    <meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
    <meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://exp.host/@hemerson/app-name"/>
    <activity 
      android:name=".MainActivity" 
      android:label="@string/app_name" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" 
      android:launchMode="singleTask" 
      android:windowSoftInputMode="adjustResize" 
      android:theme="@style/Theme.App.SplashScreen" 
      android:screenOrientation="portrait"
    >
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
      <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="my-band-scheduler"/>
        <data android:scheme="com.hemerson.appname"/>
        <data android:scheme="exp+app-name"/>
      </intent-filter>
    </activity>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
  </application>
</manifest>

package.json

{
  "name": "appName",
  "version": "1.0.0",
  "scripts": {
    "start": "expo start --dev-client",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "~1.15.0",
    "@react-native-community/datetimepicker": "3.5.2",
    "@react-native-firebase/app": "^13.0.1",
    "@react-native-firebase/auth": "^13.1.0",
    "@react-native-firebase/database": "^13.0.1",
    "@react-native-google-signin/google-signin": "^7.0.1",
    "@react-navigation/drawer": "^6.1.8",
    "@react-navigation/native": "^6.0.6",
    "@react-navigation/native-stack": "^6.2.5",
    "axios": "^0.24.0",
    "expo": "~43.0.0",
    "expo-blur": "~10.0.3",
    "expo-calendar": "~10.0.3",
    "expo-clipboard": "~2.0.3",
    "expo-dev-client": "^0.6.3",
    "expo-notifications": "~0.13.3",
    "expo-random": "~12.0.1",
    "expo-sharing": "~10.0.3",
    "expo-status-bar": "~1.1.0",
    "expo-updates": "~0.10.13",
    "intl": "^1.2.5",
    "lottie-react-native": "4.0.3",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-native": "0.64.3",
    "react-native-dotenv": "^3.3.0",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-reanimated": "~2.2.0",
    "react-native-safe-area-context": "3.3.2",
    "react-native-screens": "~3.8.0",
    "react-native-swipe-list-view": "^3.2.9",
    "react-native-web": "0.17.1",
    "react-native-webview": "11.13.0",
    "styled-components": "^5.3.3"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/firebase": "^3.2.1",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.64.12",
    "@types/react-native-dotenv": "^0.2.0",
    "@types/styled-components": "^5.1.15",
    "@types/styled-components-react-native": "^5.1.2",
    "typescript": "~4.3.5"
  },
  "private": true
}

MainActivity.java

package com.hemerson.mybandscheduler;
import expo.modules.devmenu.react.DevMenuAwareReactActivity;
import android.content.Intent;
import expo.modules.devlauncher.DevLauncherController;

import android.os.Bundle;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

import expo.modules.ReactActivityDelegateWrapper;

public class MainActivity extends DevMenuAwareReactActivity {

  @Override
  public void onNewIntent(Intent intent) {
      if (DevLauncherController.tryToHandleIntent(this, intent)) {
         return;
      }
      super.onNewIntent(intent);
  }

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // Set the theme to AppTheme BEFORE onCreate to support 
    // coloring the background, status bar, and navigation bar.
    // This is required for expo-splash-screen.
    setTheme(R.style.AppTheme);
    super.onCreate(null);
  }

  /**
   * Returns the name of the main component registered from JavaScript.
   * This is used to schedule rendering of the component.
   */
  @Override
  protected String getMainComponentName() {
    return "main";
  }

  @Override
  protected ReactActivityDelegate createReactActivityDelegate() {
    return DevLauncherController.wrapReactActivityDelegate(this, () -> new ReactActivityDelegateWrapper(
      this,
      new ReactActivityDelegate(this, getMainComponentName()) {
      @Override
      protected ReactRootView createRootView() {
        return new RNGestureHandlerEnabledRootView(MainActivity.this);
      }
    }));
  }
}

help me please. I've been trying to solve this for 3 days now.



Solution 1:[1]

On the Apps page, select an app to open the dashboard for that app. On the Dashboard, navigate to Settings > Advanced > Security > Client token.

before this line

FacebookSdk.sdkInitialize(this );

add this

FacebookSdk.setClientToken("Client token");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Syed Hasan