Unity: 5.3.4f1
GPG: GooglePlayGames.PluginVersion.VersionString = "0.9.34"
Every time the Unity is building APK it produces a following trace:
NullReferenceException: Object reference not set to an instance of an object
at GooglePlayServices.PlayServicesResolver.OnPostprocessAllAssets (System.String[] importedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromAssetPaths) [0x00000] in F:\projects\mobile_trunk_3\frontend\Assets\PlayServicesResolver\Editor\PlayServicesResolver.cs:104
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d0] in /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.
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000eb] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115
at UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets) [0x0004d] in C:\buildslave\unity\build\Editor\Mono\AssetPostprocessor.cs:27
UnityEditor.AssetDatabase:Refresh(ImportAssetOptions)
UnityEditor.AssetDatabase:Refresh() (at C:\buildslave\unity\build\artifacts\generated\common\editor\AssetDatabaseBindings.gen.cs:244)
GooglePlayGames.Editor.GPGSUpgrader:.cctor() (at Assets\GooglePlayGames\Editor\GPGSUpgrader.cs:107)
System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor(IntPtr)
System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor(RuntimeTypeHandle) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Runtime.CompilerServices/RuntimeHelpers.cs:101)
UnityEditor.EditorAssemblies:ProcessEditorInitializeOnLoad(Type) (at C:\buildslave\unity\build\Editor\Mono\EditorAssemblies.cs:123)
UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes() (at C:\buildslave\unity\build\Editor\Mono\EditorAssemblies.cs:139)
UnityEditor.EditorAssemblies:SetLoadedEditorAssemblies(Assembly[]) (at C:\buildslave\unity\build\Editor\Mono\EditorAssemblies.cs:63)
(Filename: Assets/PlayServicesResolver/Editor/PlayServicesResolver.cs Line: 104)
As I understand it is result of calling:
if (!Resolver.ShouldAutoResolve(importedAssets, deletedAssets,
movedAssets, movedFromAssetPaths))
before initializing Resolver:
public static IResolver RegisterResolver(IResolver resolverImpl)
Did not dug into it deeper yet.
I looked into it a bit more and found the source of the problem.
ResolverVer1_1 and ResolverVer1_2 both have static constructors which may call PlayServiceResolver.RegisterResolver().
unfortunately order of calling static constructors is undefined so it is indeed possible that PlayServicesResolver.OnPostprocessAllAssets is called before initialization of ResolverVer1_2.
That is wrong that code depends on order of initialization of static constructors, to say the least.
In my sources I fixed it ugly way by adding public static bool variable to class ResolverVer1_2 and then query for it's value just before calling "Resolver.ShouldAutoResolve()". According to book it should trigger initialization of static constructor. But definitely this fix is provisional and problem requires more love.
Is the hack the only way around this?
We're working on an update to the jar resolver which should make it much more reliable in situations like this. Stay Tuned!
The resolver has been re-designed and updated in 0.9.35 and works much better.
Most helpful comment
I looked into it a bit more and found the source of the problem.
ResolverVer1_1 and ResolverVer1_2 both have static constructors which may call PlayServiceResolver.RegisterResolver().
unfortunately order of calling static constructors is undefined so it is indeed possible that PlayServicesResolver.OnPostprocessAllAssets is called before initialization of ResolverVer1_2.
That is wrong that code depends on order of initialization of static constructors, to say the least.
In my sources I fixed it ugly way by adding public static bool variable to class ResolverVer1_2 and then query for it's value just before calling "Resolver.ShouldAutoResolve()". According to book it should trigger initialization of static constructor. But definitely this fix is provisional and problem requires more love.