Search code examples
unity-game-engineandroid-gradle-pluginfacebook-unity-sdk

Facebook SDK for Unity - error after import to nonempty project


Since yesterday I'm trying to resolve issues with Facebook SDK for Unity. I tried it out on completely empty Unity project and everything works fine. I can build it and run on Android device without any problems.

So, I thought I can import package to my game in the same way, but I couldn't be more wrong. Immediately after import I got this 2 errors:

ArgumentNullException: Argument cannot be null. Parameter name: path

System.String.StartsWith (System.String value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/String.cs:1549)
GooglePlayServices.PlayServicesResolver.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:27)

ArgumentNullException: Argument cannot be null. Parameter name: path

System.IO.Directory.CreateDirectory (System.String path) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/Directory.cs:75)
GooglePlayServices.PlayServicesResolver.ResolveUnsafe (System.Action`1 resolutionComplete, Boolean forceResolution)
GooglePlayServices.PlayServicesResolver+<Resolve>c__AnonStorey11.<>m__19 ()
GooglePlayServices.PlayServicesResolver.ExecuteNextResolveJob ()
GooglePlayServices.PlayServicesResolver.Resolve (System.Action resolutionComplete, Boolean forceResolution, System.Action`1 resolutionCompleteWithResult)
GooglePlayServices.PlayServicesResolver.AutoResolve ()
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:183)

When I try to run project despite of this errors, I got new ones:

Gradle failed to fetch dependencies.

Failed to run 'C:\GameDev\AbstractRhythm\Temp\PlayServicesResolverGradle\gradlew.bat -b "C:\GameDev\AbstractRhythm\Temp\PlayServicesResolverGradle\PlayServicesResolver.scripts.download_artifacts.gradle" --no-daemon "-PANDROID_HOME=C:\Users\adrso\AppData\Local\Android\Sdk" "-PTARGET_DIR=C:\GameDev\AbstractRhythm\Assets\Plugins\Android" "-PMAVEN_REPOS=" "-PPACKAGES_TO_COPY=com.android.support:support-v4:25.3.1;com.android.support:appcompat-v7:25.3.1;com.android.support:cardview-v7:25.3.1;com.android.support:customtabs:25.3.1"'
stdout:

ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files (x86)\Java\jdk1.7.0_55

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.

stderr:

exit code: 1

UnityEngine.Debug:LogError(Object)
Google.Logger:Log(String, LogLevel)
GooglePlayServices.PlayServicesResolver:Log(String, LogLevel)
GooglePlayServices.<GradleResolution>c__AnonStorey14:<>m__20(Result)
GooglePlayServices.<GradleResolution>c__AnonStorey15:<>m__29()
GooglePlayServices.PlayServicesResolver:PumpUpdateQueue()
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()

NullReferenceException: Object reference not set to an instance of an object

GooglePlayServices.AndroidSdkManager+<Create>c__AnonStoreyA.<>m__C (GooglePlayServices.AndroidSdkPackageCollection packages)
GooglePlayServices.SdkManager+<QueryPackages>c__AnonStorey9.<>m__B (GooglePlayServices.Result result)
GooglePlayServices.SdkManagerUtil+<QueryPackages>c__AnonStorey4.<>m__4 (GooglePlayServices.Result result)
GooglePlayServices.CommandLineDialog+ProgressReporter.Update (GooglePlayServices.CommandLineDialog window)
GooglePlayServices.CommandLineDialog.Update ()
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:291)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:284)
UnityEditor.HostView.SendUpdate () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:363)
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:183)

I use: Facebook SDK for Unity version 7.13.0, Unity version 2018.1.0f2, Android API 28, Android SDK Build-Tools 28, Android SDK Platform-Tools 25.0.3, Android SDK Tools 25.2.4, Google Play services 49

Do you have any idea what's going on?


Solution

  • It required few steps to solve this problem:

    1. Compare Assets/Plugins/Android/AndroidManifest.xml of unworking project with empty project that only have Facebook SDK.
    2. Use Assets -> Play Services Resolver -> Android Resolver -> Force Resolve.
    3. Check "Environment variables" in Windows, it turned out I had path to new JDK as well as old - remove old entry.
    4. Make sure you don't have any app using same Facebook app ID on your device, you can only have one at a time.

    I hope someone will save time thanks to this :)