Unity Facebook plugin FacebookContentProvider not found runtime exception.

I add facebook plugin to my project, follow all the steps.It is working fine in unity editor. when i tried exporting a build and tested on android device it is not working. The app crash on the initial launch itself.It closes immediately.

I tried connecting the app to the adb logcat and found some errors on the log, which is follows.

java.lang.RuntimeException: Unable to get provider com.facebook.FacebookContentProvider: java.lang.ClassNotFoundException: Didn’t find class “com.facebook.FacebookContentProvider” on path: DexPathList[[zip file “/data/app/com.studio.halfo-1/base.apk”],nativeLibraryDirectories=[/data/app/com.studio.halfo-1/lib/arm, /data/app/com.studio.halfo-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5175)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4767)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.access$1600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Caused by: java.lang.ClassNotFoundException: Didn’t find class “com.facebook.FacebookContentProvider” on path: DexPathList[[zip file “/data/app/com.studio.halfo-1/base.apk”],nativeLibraryDirectories=[/data/app/com.studio.halfo-1/lib/arm, /data/app/com.studio.halfo-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.ActivityThread.installProvider(ActivityThread.java:5160)
… 10 more
Suppressed: java.lang.ClassNotFoundException: com.facebook.FacebookContentProvider
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)

If i tried commenting the FacebookContentProvider in the AndroidManifest.xml file then the app fails on the facebook initialisation. It throws Facebook is not initialised error.

Anyone Please let me know what i am missing on this. My Unity Version is 2018.4.3f1.

,I add facebook plugin to my project, follow all the steps.It is working fine in unity editor. when i tried exporting a build and tested on android device it is not working. The app crash on the initial launch itself.It closes immediately.

I tried connecting the app to the adb logcat and found some errors on the log, which is follows.

java.lang.RuntimeException: Unable to get provider com.facebook.FacebookContentProvider: java.lang.ClassNotFoundException: Didn’t find class “com.facebook.FacebookContentProvider” on path: DexPathList[[zip file “/data/app/com.studio.halfo-1/base.apk”],nativeLibraryDirectories=[/data/app/com.studio.halfo-1/lib/arm, /data/app/com.studio.halfo-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
at android.app.ActivityThread.installProvider(ActivityThread.java:5175)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4767)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4707)
at android.app.ActivityThread.access$1600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1412)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Caused by: java.lang.ClassNotFoundException: Didn’t find class “com.facebook.FacebookContentProvider” on path: DexPathList[[zip file “/data/app/com.studio.halfo-1/base.apk”],nativeLibraryDirectories=[/data/app/com.studio.halfo-1/lib/arm, /data/app/com.studio.halfo-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.ActivityThread.installProvider(ActivityThread.java:5160)
… 10 more
Suppressed: java.lang.ClassNotFoundException: com.facebook.FacebookContentProvider
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)

If i tried commenting the FacebookContentProvider in the AndroidManifest.xml file then the app fails on the facebook initialisation. It throws Facebook is not initialised error.

Anyone Please let me know what i am missing on this. My Unity Version is 2018.4.3f1.

I struggled with the same thing. Crashing on android at the very startup with the provider class not found" error. I was just trying to FB login from the Unity app and get profile picture and name.

I used the latest available FB for Unity SDK (v7.18.0 ). Banged my head around quite a bit - changing AndroidManifest, changing the gradle, messing around with proguard file etc. Nothing worked.

Finally I solved it by using a previous version of Facebook SDK (v7.15. Ithink). This version has a bigger footprint and more libraries. I didn’t face the FacebookContentProvider not found problem any more and after a bit of struggle ( duplicate classes and linking issues), I got the build to work on android…

IMHO, the current Facebook SDK version for Unity looks stunted and incomplete. I raised a bug report with no response to date.

Hello guys

I am also facing the same issue I’m using Unity version 2017.4.27f1.

hoping to get some answers to the same.

I’m facing the same issue on Unity 2019.3.0f6 with Facebook SDK 7.18.1. Hope to find out solution

@GunLengend , try to make “clear” resolve of packages:

  1. “/Assets/Play Service Resolver/Android Resolver/Delete Resolved Libraries”
  2. “/Assets/Play Service Resolver/Android Resolver/Resolve”

Should work now (at least works for me FB 7.18.1 & Unity 2019.2.17f1)

Facebook Unity SDK Proper Setup and Fixing Didn't find class com.facebook.FacebookContentProvider

  • Overview

The step by step process of getting the Unity side of FB setup and running by importing the right packages. Also fixes the error – Error AndroidRuntime java.lang.RuntimeException: Unable to get provider com.facebook.FacebookContentProvider: java.lang.ClassNotFoundException: Didn't find class "com.facebook.FacebookContentProvider…”

  • Steps

  1. Delete any previous Unity Facebook SDKs and re-import the latest. Follow the steps here: Unity Can't build android with facebook sdk - Stack Overflow
    • Delete Facebook SDK folder.

• Delete `PlayServicesResolver folder.

• Delete Plugins Folder.

• Now comment the code using Facebook API and namespaces.

• Now import latest FacebookSDK and configure it with project details in Edit-setting option. In Assets->ImportPackage->CustomPackage->latestFBUnityPackage
In my case it was “facebook-unity-sdk-11.0.0”

• Now regenerate Android Manifest file and uncomment the code.

  1. Delete the Assets\PlayServicesResolver Folder again

  2. Download the ExternalDependencyManager and unzip, from here: GitHub - googlesamples/unity-jar-resolver: Unity plugin which resolves Android & iOS dependencies and performs version management

  3. In Unity import the “external-dependency-manager-latest” unity package

  4. If the Unity Menu
    “Assets->ExternalDependencyManager”
    does not showup goto
    Assets\ExternalDependencyManager\Editor\1.2.171,
    select all the DLLs (in my case
    there were four). Then In the Unity
    Inspector for the four DLLs select
    INCLUDE PLATFORMS->EDITOR. Then hit
    the “Apply” button

  5. In Unity Assets\FacebookSDK\Plugins\Editor\Dependencies – change the 12 to 11.3.

`
    androidPackage spec="com.facebook.android:facebook-core:[11.0, 11.3)" />
    androidPackage spec="com.facebook.android:facebook-applinks:[11.0, 11.3)" />
    androidPackage spec="com.facebook.android:facebook-login:[11.0, 11.3)" />
    androidPackage spec="com.facebook.android:facebook-share:[11.0, 11.3)" />
    androidPackage spec="com.facebook.android:facebook-gamingservices:[11.0, 11.3)" />
`
  1. In Unity->Player Settings->Android->Publishing – Build – Check the boxes to generate the following: Custom Main Manifest; Custom Main Gradle Template; Custom Gradle Properties Template; Custom Proguard File

  2. In Assets\Plugins\Android – proguard-user.txt – add the following two lines:

`
    -keep class com.facebook.internal.** {public *;}
    -keep class com.facebook.** {public *; }
`
  1. In the Unity dropdown menu, select the following option to Resolve the Android dependencies: Assets->ExternalDependencyManager->Android->Resolve
    Step 9: Solution From - Android app crash on launch due to ClassNotFoundException for "com.facebook.FacebookContentProvider" · Issue #509 · facebook/facebook-sdk-for-unity · GitHub

  2. The error should be resolved and you should be able to run your app with the Facebook SDK. If it doesn’t work, keep working at it, you will get it!