Skip to content

[Bug] Building an Android project in Unity 2021.2.0b1 (beta) may cause a runtime exception in the Unity Editor when looking up GetApplicationIdentifier in UnityCompat.cs. #447

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
patm1987 opened this issue Jun 24, 2021 · 5 comments

Comments

@patm1987
Copy link
Collaborator

[READ] For Firebase Unity SDK issues, please report to Firebase Unity Sample

Once you've read this section and determined that your issue is appropriate for this repository, please delete this section.

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2021.2.0b1.3029
  • External Dependency Manager version: 1.2.162
  • Source you installed EDM4U: .unitypackage
  • Features in External Dependency Manager in use: Android Resolver
  • Plugins SDK in use: Google Play
  • Platform you are using the Unity editor on: Windows

[REQUIRED] Please describe the issue here:

After performing an Android build (and every time launching the editor after that build), Unity repeatedly logs:

AmbiguousMatchException: Ambiguous match found.
  at System.RuntimeType.GetMethodImplCommon (System.String name, System.Int32 genericParameterCount, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConv, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00050] in <fd976842c3634855aba83404a44c7daa>:0 
  at System.RuntimeType.GetMethodImpl (System.String name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Reflection.CallingConventions callConv, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00000] in <fd976842c3634855aba83404a44c7daa>:0 
  at System.Type.GetMethod (System.String name, System.Reflection.BindingFlags bindingAttr) [0x0000e] in <fd976842c3634855aba83404a44c7daa>:0 
  at System.Type.GetMethod (System.String name) [0x00000] in <fd976842c3634855aba83404a44c7daa>:0 
  at GooglePlayServices.UnityCompat.GetUnity56AndAboveApplicationIdentifier (UnityEditor.BuildTarget buildTarget) [0x00000] in /Users/chkuang/Workspace/Git/unity-jar-resolver/source/AndroidResolver/src/UnityCompat.cs:446 
  at GooglePlayServices.UnityCompat.GetApplicationId (UnityEditor.BuildTarget buildTarget) [0x00000] in /Users/chkuang/Workspace/Git/unity-jar-resolver/source/AndroidResolver/src/UnityCompat.cs:500 
  at GooglePlayServices.PlayServicesResolver.GetAndroidApplicationId () [0x00000] in /Users/chkuang/Workspace/Git/unity-jar-resolver/source/AndroidResolver/src/PlayServicesResolver.cs:1041 
  at GooglePlayServices.PlayServicesResolver.<PollBundleId>m__36 () [0x00000] in /Users/chkuang/Workspace/Git/unity-jar-resolver/source/AndroidResolver/src/PlayServicesResolver.cs:1429 
  at GooglePlayServices.PlayServicesResolver+PropertyPoller`1[T].Poll (System.Func`1[TResult] getCurrentValue, GooglePlayServices.PlayServicesResolver+PropertyPoller`1+Changed[T] changed) [0x0002f] in /Users/chkuang/Workspace/Git/unity-jar-resolver/source/AndroidResolver/src/PlayServicesResolver.cs:343 
  at GooglePlayServices.PlayServicesResolver.PollBundleId () [0x00000] in /Users/chkuang/Workspace/Git/unity-jar-resolver/source/AndroidResolver/src/PlayServicesResolver.cs:1429 
  at UnityEditor.EditorApplication.Internal_CallUpdateFunctions () [0x00032] in <ca192453d8394227952a14f40675979e>:0 

The issue appears to be this line:

        var getApplicationIdentifierMethod =
            typeof(UnityEditor.PlayerSettings).GetMethod("GetApplicationIdentifier");

Further investigation reveals that Unity defines both:

public static string GetApplicationIdentifier(NamedBuildTarget buildTarget)

and

public static string GetApplicationIdentifier(BuildTargetGroup targetGroup)

The solution is likely to request the implementation of the method that takes a BuildTargetGroup to eliminate the conflicting name and allow this code to work:

      BuildTargetGroup buildTargetGroup = UnityCompat.ConvertBuildTargetToBuildTargetGroup(buildTarget);
      if (buildTargetGroup == BuildTargetGroup.Unknown)
        return (string) null;
      return method.Invoke((object) null, new object[1]
      {
        (object) buildTargetGroup
      }) as string;

Please answer the following, if applicable:

What's the issue repro rate? 100%

What happened? How can we make the problem occur?
Add a plugin that uses EDM4U to a Unity 2021.2.0b1 project. After building for Android, you should start to see these logs. Tested in both Firebase and with the Play plugin for Unity.

If you have a downloadable sample project that reproduces the bug you're reporting, you will
likely receive a faster response on your issue.

@joaquingrech
Copy link

Yeah this is the same problem I reported last week at #440
I warned that people would begin coming here as soon as Unity got out to public beta with this bug... and not much was done about it :(

@DellaBitta DellaBitta removed the new to be triaged label Jun 25, 2021
@patm1987
Copy link
Collaborator Author

I created a PR that may fix it: #449

@DellaBitta
Copy link
Collaborator

Thanks for the amazin ticket @patm1987! As mentioned, the discovery of this issue is being tracked already so I'm going to close this issue as a Duplicate #440. Thanks!

@chkuang-g
Copy link
Collaborator

chkuang-g commented Jun 29, 2021

Reopen the bug until we check the PR #449

@chkuang-g chkuang-g reopened this Jun 29, 2021
@chkuang-g
Copy link
Collaborator

chkuang-g commented Jun 29, 2021

Reviewed. #449 looks like a valid fix. Will comment on #440 for visibility

chkuang-g added a commit that referenced this issue Jun 30, 2021
- Version 1.2.166 - Jun 30, 2021
* All - Fixed #440 and fixed #447 by specifying the parameter type while calling
  `GetApplicationIdentifier()` Unity API using reflection, due to a new
  overloaded method introduced in Unity 2021.2.
* Android Resolver - Fixed #442 by patching `Dependency.IsGreater()` when the
  version strings end '+'.

Change-Id: I45b335d7c196d6b4d03e940b3b0f87f2767a5495
@googlesamples googlesamples locked and limited conversation to collaborators Jul 30, 2021
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

4 participants