facebook / facebook-sdk-for-unity

The facebook sdk for unity.
https://developers.facebook.com/docs/unity
Other
490 stars 257 forks source link

Initialization error on Android #109

Open edscodeblenders opened 7 years ago

edscodeblenders commented 7 years ago

Hello,

I'm trying to integrate the Facebook SDK in my Unity game, but the initialization fails. I'm using the SDK version 7.8 because newer versions make my game exceed the 64K methods limit, and I don't want to make it multi-dex. This is what I see in Android Logcat: 10-10 18:40:25.495 11528-11624/? V/com.facebook.unity.FB: SetUserAgentSuffix(Unity.7.8.0) 10-10 18:40:25.522 11528-11624/? V/com.facebook.unity.FB: Init({"appId":"842765265887515"}) 10-10 18:40:25.532 11528-11624/? I/art: Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/BaseFragmentActivityApi16; 10-10 18:40:25.532 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2) 10-10 18:40:25.532 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer.c(com.unity3d.player.UnityPlayer) ((null):-1) 10-10 18:40:25.532 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer$c$1.handleMessage(android.os.Message) ((null):-1) 10-10 18:40:25.532 11528-11624/? I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:98) 10-10 18:40:25.532 11528-11624/? I/art: at void android.os.Looper.loop() (Looper.java:154) 10-10 18:40:25.532 11528-11624/? I/art: at void com.unity3d.player.UnityPlayer$c.run() ((null):-1) 10-10 18:40:25.532 11528-11624/? I/art: Caused by: java.lang.ClassNotFoundException: android.support.v4.app.BaseFragmentActivityApi16 10-10 18:40:25.532 11528-11624/? I/art: at java.lang.Class java.lang.VMClassLoader.findLoadedClass!(java.lang.ClassLoader, java.lang.String) (VMClassLoader.java:-2) 10-10 18:40:25.532 11528-11624/? I/art: at java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) (ClassLoader.java:742) 10-10 18:40:25.532 11528-11624/? I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:362) 10-10 18:40:25.532 11528-11624/? I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312) 10-10 18:40:25.532 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2) 10-10 18:40:25.532 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer.c(com.unity3d.player.UnityPlayer) ((null):-1) 10-10 18:40:25.532 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer$c$1.handleMessage(android.os.Message) ((null):-1) 10-10 18:40:25.532 11528-11624/? I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:98) 10-10 18:40:25.532 11528-11624/? I/art: at void android.os.Looper.loop() (Looper.java:154) 10-10 18:40:25.532 11528-11624/? I/art: at void com.unity3d.player.UnityPlayer$c.run() ((null):-1) 10-10 18:40:25.532 11528-11624/? I/art: Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/BaseFragmentActivityApi16; 10-10 18:40:25.532 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2) 10-10 18:40:25.532 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer.c(com.unity3d.player.UnityPlayer) ((null):-1) 10-10 18:40:25.532 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer$c$1.handleMessage(android.os.Message) ((null):-1) 10-10 18:40:25.533 11528-11624/? I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:98) 10-10 18:40:25.533 11528-11624/? I/art: at void android.os.Looper.loop() (Looper.java:154) 10-10 18:40:25.533 11528-11624/? I/art: at void com.unity3d.player.UnityPlayer$c.run() ((null):-1) 10-10 18:40:25.533 11528-11624/? I/art: Caused by: java.lang.ClassNotFoundException: android.support.v4.app.BaseFragmentActivityApi16 10-10 18:40:25.533 11528-11624/? I/art: at java.lang.Class java.lang.VMClassLoader.findLoadedClass!(java.lang.ClassLoader, java.lang.String) (VMClassLoader.java:-2) 10-10 18:40:25.533 11528-11624/? I/art: at java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) (ClassLoader.java:742) 10-10 18:40:25.533 11528-11624/? I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:362) 10-10 18:40:25.533 11528-11624/? I/art: at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312) 10-10 18:40:25.533 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2) 10-10 18:40:25.533 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer.c(com.unity3d.player.UnityPlayer) ((null):-1) 10-10 18:40:25.533 11528-11624/? I/art: at boolean com.unity3d.player.UnityPlayer$c$1.handleMessage(android.os.Message) ((null):-1) 10-10 18:40:25.533 11528-11624/? I/art: at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:98) 10-10 18:40:25.533 11528-11624/? I/art: at void android.os.Looper.loop() (Looper.java:154) 10-10 18:40:25.533 11528-11624/? I/art: at void com.unity3d.player.UnityPlayer$c.run() ((null):-1) 10-10 18:40:25.609 11528-11624/? E/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/FacebookActivity;

Any idea of what could be happening here?

Thanks.

sp-jordi-vilalta commented 6 years ago

I was having a similar stack trace, but it didn't finish there: scrolling to the end it showed the final cause was that it couldn't load some class from android.arch. After some research I discovered that this was caused by release 26.1.0 of the support library (https://developer.android.com/topic/libraries/support-library/revisions.html#26-1-0) which added the "Android Architecture Components" dependency. After adding those libraries it worked.

palerdot commented 6 years ago

@sp-jordi-vilalta You saved my day. I faced the same error in react native. Only your solution worked.

GregLukosek commented 6 years ago

@sp-jordi-vilalta Thanks for the tip. Can you elaborate how you did that? I have a same issue right now. Thanks in advance

sp-jordi-vilalta commented 6 years ago

@GregLukosek I don't remember the full stack trace, but at the end it was showing the real missing class, and I think it was something from android.arch.* Recent Android projects should manage their Android dependencies using maven/gradle, but I don't know about the specifics to automate this for Unity, so I just followed the documentation in https://developer.android.com/reference/android/arch/lifecycle/package-summary.html to know the proper needed packages and versions, and downloaded them manually from the Google maven repository (https://maven.google.com). At that moment (v1.0.3), getting the runtime and common packages was enough to make it work.