Skip to content

NullReferenceException with 1.2.19.0 #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yuriy-universal-ivanov opened this issue May 5, 2017 · 8 comments
Closed

NullReferenceException with 1.2.19.0 #48

yuriy-universal-ivanov opened this issue May 5, 2017 · 8 comments

Comments

@yuriy-universal-ivanov
Copy link
Contributor

yuriy-universal-ivanov commented May 5, 2017

Hi,

Due to #47 I had to update Play Services Resolver. Now it works, but all the time logs the exception in Unity Console:

NullReferenceException: Object reference not set to an instance of an object
GooglePlayServices.ResolverVer1_1.AarPathToPackageName (System.String aarPath)
GooglePlayServices.ResolverVer1_1.FindAarExplodeDataEntry (System.String aarPath)
GooglePlayServices.ResolverVer1_1.ShouldExplode (System.String aarPath)
GooglePlayServices.ResolverVer1_1.ShouldReplaceDependency (Google.JarResolver.Dependency oldDependency, Google.JarResolver.Dependency newDependency)
GooglePlayServices.PlayServicesResolver.m__C (Google.JarResolver.Dependency oldDependency, Google.JarResolver.Dependency newDependency)
Google.JarResolver.PlayServicesSupport.CopyDependencies (System.Collections.Generic.Dictionary`2 dependencies, System.String destDirectory, Google.JarResolver.OverwriteConfirmation confirmer)
GooglePlayServices.ResolverVer1_1.DoResolutionNoAndroidPackageChecks (Google.JarResolver.PlayServicesSupport svcSupport, System.String destinationDirectory, Google.JarResolver.OverwriteConfirmation handleOverwriteConfirmation)
GooglePlayServices.ResolverVer1_1+c__AnonStorey8.<>m__10 ()
GooglePlayServices.ResolverVer1_1.DoResolution (Google.JarResolver.PlayServicesSupport svcSupport, System.String destinationDirectory, Google.JarResolver.OverwriteConfirmation handleOverwriteConfirmation, System.Action resolutionComplete)
GooglePlayServices.PlayServicesResolver.Resolve (System.Action resolutionComplete)
GooglePlayServices.PlayServicesResolver.AutoResolve ()
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/editor/EditorApplicationBindings.gen.cs:249)

Resolver 1.2.19.0, Unity 5.6, macOS.

Thank you for any help with it,
Yuriy

@claywilkinson
Copy link
Contributor

Thanks for the feedback. We'll look into it. To clarify, the aars are resolved OK, it just prints this exception in the console?

@yuriy-universal-ivanov
Copy link
Contributor Author

@claywilkinson ,
Exactly

@stewartmiles
Copy link
Contributor

On OSX 10.12.4 with Unity 5.6.0f3, I just:

  • Updated my Android SDK so that it includes 10.2.4
  • Pulled in resolver 1.2.19.0 into a project
  • Added "Google.VersionHandler.InvokeInstanceMethod(svcSupport, "DependOn", new object[] { "com.google.android.gms", "play-services-ads-lite", "LATEST" });" to an editor .cs file.
  • Ran resolution.

All dependencies are pulled into the project and no errors are reported.

Could you share a project that reproduces the issue?

Also, it would be great to share the Unity log with verbose logging enabled in the Jar Resolver so that we can figure out what's going on here.

@yuriy-universal-ivanov
Copy link
Contributor Author

yuriy-universal-ivanov commented May 6, 2017

Hi @stewartmiles ,

The issue is caused by support-v4:

Google.VersionHandler.InvokeInstanceMethod(svcSupport, "DependOn", new object[] { "com.android.support", "support-v4", "LATEST" }, namedArgs: new Dictionary<string, object>()
{
    { "packageIds", new string[] { "extra-android-m2repository" } }
});

Specifically, by "-alpha1" in the version (support-v4-26.0.0-alpha1). It happens when the appropriate library has been already added (this is why the first resolution works fine) when checking if the library has to be updated or not.
Specifically,

bool ResolverVer1_1.ShouldReplaceDependency(Dependency oldDependency, Dependency newDependency)

is called with two arguments:
oldDependency.BestVersionArtifactPath == "/com/android/support/support-v4/26.0.0/support-v4-26.0.0"
newDependency.BestVersionArtifactPath == "/Users/universal/Library/Android/sdk/extras/android/m2repository/com/android/support/support-v4/26.0.0-alpha1/support-v4-26.0.0-alpha1"
which then causes

string ResolverVer1_1.FindAarInTargetPath(string aarPath)

to return null.

I'm currently working on a fix, not sure yet how difficult it will be for me and how much time will take.

P.S. There is one more related issue: Unity Console contains warnings:

No compatible versions of com.android.support:support-v4 required by (com.google.android.gms:play-services-basement:10.2.4), will try using the latest version 26.0.0-alpha1

Found dependencies:
com.android.support:support-v4 required by (this app)
com.google.android.gms:play-services-base required by (com.google.android.gms:play-services-gcm:LATEST)
com.google.android.gms:play-services-basement required by (com.google.android.gms:play-services-gcm:LATEST)
com.google.android.gms:play-services-iid required by (com.google.android.gms:play-services-gcm:LATEST)
com.android.support:support-compat required by (com.android.support:support-v4:LATEST)
com.android.support:support-media-compat required by (com.android.support:support-v4:LATEST)
com.android.support:support-core-utils required by (com.android.support:support-v4:LATEST)
com.android.support:support-core-ui required by (com.android.support:support-v4:LATEST)
com.android.support:support-fragment required by (com.android.support:support-v4:LATEST)
com.google.android.gms:play-services-tasks required by (com.google.android.gms:play-services-base:10.2.4)
com.android.support:support-v4 required by (com.google.android.gms:play-services-basement:10.2.4)
com.android.support:support-annotations required by (com.android.support:support-compat:26.0.0-alpha1)

UnityEngine.Debug:LogWarning(Object)
GooglePlayServices.PlayServicesResolver:<PlayServicesResolver>m__B(String, LogLevel)
Google.JarResolver.PlayServicesSupport:Log(String, LogLevel, Boolean)
Google.JarResolver.PlayServicesSupport:ResolveDependencies(Boolean, Dictionary`2, String, ExplodeAar)
Google.JarResolver.PlayServicesSupport:ResolveDependencies(Boolean, String, ExplodeAar)
GooglePlayServices.ResolverVer1_1:DoResolutionNoAndroidPackageChecks(PlayServicesSupport, String, OverwriteConfirmation)
GooglePlayServices.<DoResolution>c__AnonStorey8:<>m__10()
GooglePlayServices.ResolverVer1_1:DoResolution(PlayServicesSupport, String, OverwriteConfirmation, Action)
GooglePlayServices.PlayServicesResolver:Resolve(Action)
GooglePlayServices.PlayServicesResolver:MenuResolve()

Regards,
Yuriy

@yuriy-universal-ivanov
Copy link
Contributor Author

yuriy-universal-ivanov commented May 6, 2017

Please review pull request #49.

@stewartmiles
Copy link
Contributor

Ah sorry @yuriy-universal-ivanov I missed your last issue update here. I reviewed your pull request without that context. It makes sense now. This code base does a pretty terrible job attempting to support -alpha versions strings etc. TBH we would really like to purge the maven dependency management code from this code base entirely and just use gradle to download dependencies, we have a start but there is a load of remaining work to do.

I think the problem is in the caching code in Resolver1_1.cs rather than JarResolverLib. I've pushed a potential fix for the problem.

stewartmiles pushed a commit that referenced this issue May 8, 2017
I was unable to reproduce
#48
however from the stack trace it looks like the cached target dependency
isn't found by GooglePlayServices.ResolverVer1_1.ShouldReplaceDependency().
This is very likely to be caused by the AAR cache referencing a file that
has since been deleted.

In the case the target file isn't found we simply permit the replacement
of the dependency.

Change-Id: I595e395a750362b38ed7a1a6f638a5751b45a87a
@yuriy-universal-ivanov
Copy link
Contributor Author

yuriy-universal-ivanov commented May 8, 2017

Hi @stewartmiles ,

Thanks for checking that. Well, I understand that my fix makes Play Services Resolver consider versions x.y.z-alpha & x.y.z the same, but as they were stored without that -alpha like postfixes in Plugins/Android, I thought it was done by design. Actually, as I can see from your commit:

// If we're unable to find the specified artifact then it's possible the oldDependency
// doesn't have a valid version string.
if (String.IsNullOrEmpty(artifactPath)) return true;

you didn't change that trouble anyway. Of course your change will suppress throwing the exception, but I don't think it's a very good idea to get round the issue this way. What I did in #49 is basically I applied the same rule (and the same function) for extracting version code as used to generate file names when storing them in Plugins/Android folder, so repetitive checks for versions with -alpha like postfixes don't misdetect them as a new version each time).

What your code does - is first looking for the file in FindAarInTargetPath by a wrong name (as it was stored without -alpha, but it looks for a file name with -alpha postfix). It can't locate the file of course, so it just skips. But what if I delete the stored .aar file? It will still be unable to locate the file and will just ignore that, because of your if (String.IsNullOrEmpty(artifactPath)) return true;, so the library will not be resolved.

I believe my approach is much more correct. Besides, I've tested it, and it seems to work completely well. Even those warnings I've mentioned above gone (though I'm not sure that it's indeed my change caused that, maybe they are just shown only once).

I hope I explained it clear enough. Please correct me wherever I'm wrong.

Regards,
Yuriy

yuriy-universal-ivanov added a commit to universal-tools/unity-jar-resolver that referenced this issue May 8, 2017
Using the same rule (and the same function) for extracting a version code when comparing libraries versions, as used to generate file names when storing them in Plugins/Android folder, so repetitive checks for versions with -alpha like postfixes don't misdetect them as a new version each time.
@stewartmiles
Copy link
Contributor

Thanks for the explanation @yuriy-universal-ivanov your patch sounds good. Just need the commit message updated to describe what's going on in the patch so that other folks don't come across the change and ask the same questions I have asked.

stewartmiles pushed a commit that referenced this issue May 8, 2017
stewartmiles pushed a commit that referenced this issue May 12, 2017
For more information see:
#48

Change-Id: I2181106e9b2cb87a98aa16a675ae095a0627c930
@googlesamples googlesamples locked and limited conversation to collaborators Nov 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants