facebook / facebook-sdk-for-unity

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

[Android] Not working with Android Support v26.x.x libs #125

Open djbozkosz opened 6 years ago

djbozkosz commented 6 years ago

Dear developers,

I'm trying latest version (7.10.1) of SDK in Unity 5.6.2p3. Everything works fine with Android Support v25.x.x libs. But we need to target Android API 26 and use support libs of this version (due notification API changes). Unfortunately SDK doesn't work with this version and throws exceptions while plugin inits:

Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/arch/lifecycle/LifecycleOwner; at void com.facebook.internal.Validate.hasFacebookActivity(android.content.Context, boolean) (Validate.java:216) at void com.facebook.FacebookSdk.sdkInitialize(android.content.Context, com.facebook.FacebookSdk$InitializeCallback) (FacebookSdk.java:265) at void com.facebook.unity.FB.Init(java.lang.String) (FB.java:86) at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2) at boolean com.unity3d.player.UnityPlayer.c(com.unity3d.player.UnityPlayer) ((null):-1) at boolean com.unity3d.player.UnityPlayer$c$1.handleMessage(android.os.Message) ((null):-1) at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:98) at void android.os.Looper.loop() (Looper.java:154) at void com.unity3d.player.UnityPlayer$c.run() ((null):-1) Caused by: java.lang.ClassNotFoundException: Didn't find class "android.arch.lifecycle.LifecycleOwner" on path: DexPathList[[zip file "/data/app/com.test.example-1/base.apk"],nativeLibraryDirectories=[/data/app/com.test.example-1/lib/arm, /data/app/com.test.example-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]] at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56) at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380) at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312) at void com.facebook.internal.Validate.hasFacebookActivity(android.content.Context, boolean) (Validate.java:216) at void com.facebook.FacebookSdk.sdkInitialize(android.content.Context, com.facebook.FacebookSdk$InitializeCallback) (FacebookSdk.java:265) at void com.facebook.unity.FB.Init(java.lang.String) (FB.java:86) at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2) at boolean com.unity3d.player.UnityPlayer.c(com.unity3d.player.UnityPlayer) ((null):-1) at boolean com.unity3d.player.UnityPlayer$c$1.handleMessage(android.os.Message) ((null):-1) at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:98) at void android.os.Looper.loop() (Looper.java:154) at void com.unity3d.player.UnityPlayer$c.run() ((null):-1)

Attaching list of used libs:

animated-vector-drawable-26.1.0.aar appcompat-v7-26.1.0.aar cardview-v7-26.1.0.aar customtabs-26.1.0.aar support-annotations-26.1.0.jar support-compat-26.1.0.aar support-core-ui-26.1.0.aar support-core-utils-26.1.0.aar support-fragment-26.1.0.aar support-media-compat-26.1.0.aar support-v4-26.1.0.aar support-vector-drawable-26.1.0.aar

I checked Android Manifest after merge, all FB activities are included and checked DEX file and FB classes are included too.

I also tried to replace (just for test) FB Android SDK (v4.23.0) with v4.29.0 and I'm able to init plugin but login is not possible - or another dialog based action -> ends with similar set of exceptions.

Best regards Tomáš Růžička.

djbozkosz commented 6 years ago

Ok, for now we resolved issue by adding Lifecycle libs:

from android.arch.core:

common-1.0.0.jar runtime-1.0.0.aar

from android.arch.lifecycle:

common-1.0.3.jar compiler-1.0.0.jar extensions-1.0.0.aar reactivestreams-1.0.0.aar runtime-1.0.3.aar

Note: for non Gradle builds in Unity you need to move all stuff with ${applicationId} from aar's manifests into your manifest with correct package name. And (probably too) remove target sdk version from FB manifests.

haswalt commented 6 years ago

I also have this issue, trying to make push notifications work.

an official fix / word on this would be ideal

hashtagsheep commented 6 years ago

Same here, would be nice to get this fixed

q3francy commented 6 years ago

Same here, would be nice to get this fixed

matias-leez commented 6 years ago

I have the same problem.

JimmyDeemo commented 6 years ago

I think that #109 has your answer. The support libs added a dependency, which in regular Android projects can be downloaded using a remote repository. I don't think this step is added by default when building in Unity.

jnbt commented 6 years ago

I think the resolution should automatically download these dependencies, but there was a bug in the unity-jar-resolver which leads to overwritten libraries: https://github.com/googlesamples/unity-jar-resolver/issues/97

This is exactly the case with android.arch.core.* and android.arch.lifecycle.*.

This is already fixed in recent releases BUT it seems to me that you need to delete the Temp folder, all already resolved dependencies from Plugins/Android and ProjectSettings/AndroidResolverDependencies.xml

JimmyDeemo commented 6 years ago

Thanks for the update @jnbt, so you are saying the the Jar Resolver plugin should be able to recognise the dependency, which comes from within an existing .aar file, and down load that in addition to the .aar dependencies?

To confirm, we should clear down all resolved dependencies and settings, update Jar Resolver and resolve?

jnbt commented 6 years ago

@JimmyDeemo I've tried again and it worked.

Maybe someone else can try the following steps:

  1. Close Unity (to prevent any auto-resolution by the Jar Resolver)
  2. Remove all dependencies managed by the Android Jar Resolver (every non-custom *.jar and *.aar file in Assets/Plugins/Android.
  3. Remove the Temp-folder completely
  4. Remove ProjectSettings/AndroidResolverDependencies.xml
  5. Open the project in Unity and wait for the Jar Resolver to do it's work (or in case you have disabled auto-resolution, Assets -> Android Resolver -> Resolve