Bug 54383 - AppLinks Package Causes Crash at Launch After Updating Google Play Services Packages
Summary: AppLinks Package Causes Crash at Launch After Updating Google Play Services P...
Status: IN_PROGRESS
Alias: None
Product: Forms
Classification: Xamarin
Component: Android (show other bugs)
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-04-01 17:40 UTC by Philipp Sumi
Modified: 2017-10-12 11:39 UTC (History)
12 users (show)

See Also:
Tags: ac android applinks playservices xamextfollowed fr
Is this bug a regression?: ---
Last known good build:


Attachments
packages.config file (6.82 KB, application/xml)
2017-04-04 07:25 UTC, Philipp Sumi
Details
repro project (50.36 KB, application/x-zip-compressed)
2017-06-06 16:13 UTC, Jimmy [MSFT]
Details

Description Philipp Sumi 2017-04-01 17:40:58 UTC
Tried to integrate app links into my app (Xamarin Forms) and thus referenced the latest (pre-6) AppLinks NuGet. This alone (without even registering the library) crashes my app at runtime. Same goes if I actually add the registration call in MainActivity:

    AndroidAppLinks.Init(this);

Using a stable package isn't an option since they have a hard dependency on outdated Google libs. So I'm basically not writing any code, and the app crashes hard on me.
Maybe noteworthy: VS 2017 seems to have downloaded and decompressed some support libraries as part of the NuGet setup. That seemed to have worked though.




System.TypeLoadException: Could not load type 'Xamarin.Forms.Platform.Android.AppLinks.AndroidAppLinks' from assembly 'Xamarin.Forms.Platform.Android.AppLinks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

  at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00023] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:671 
  at System.Reflection.MonoCMethod.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00089] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:652 
  at System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:680 
  at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) [0x00243] in /Users/builder/data/lanes/4009/f3074d2c/source/mono/mcs/class/referencesource/mscorlib/system/rttype.cs:5394
Comment 1 Jimmy [MSFT] 2017-04-03 16:46:51 UTC
Hey Philipp, I couldn't reproduce this with a new project by just adding the Android App Links package or even after calling

>  AndroidAppLinks.Init(this);

It sounds like you also updated the Google Play Services packages? Can you share a list of the packages and their versions in your project so I can make sure I am using the same? 

I'm also unclear what you mean by:

> VS 2017 seems to have downloaded and decompressed some support libraries as part of the NuGet setup. That seemed to have worked though.

Do you mean the downloads completed successfully, or that you no longer experienced the app crash after the of the support libraries were downloaded?
Comment 2 Philipp Sumi 2017-04-04 07:23:49 UTC
Hi Jimmy

As far as packages go, please find attached the packages file of my Android project. I installed the Nuget only in that project and not the PCL project (assuming that's correct since it's needed for Android only). This is now (I removed the AppLinks package since I couldn't run the app anymore).

I did mean that the downloads completed successfully during the NuGet install, so that didn't seem to be a reason for a crash (which happened after all that).
Comment 3 Philipp Sumi 2017-04-04 07:25:25 UTC
Created attachment 21167 [details]
packages.config file

As requested, the packages.config file of my Android project (after uninstalling the failing NuGet package and the Google AppIndexing package that it depends on).
Comment 4 mtwsm 2017-04-28 16:30:33 UTC
Hi Jimmy, Hi Philipp,

We have the exact same issue and we desperately need some help to fix it.
Is there any advances about it ?

Thank you in advance for your answers and wish you a good weekend !
Best regards,
Comment 5 Jimmy [MSFT] 2017-06-06 16:12:28 UTC
I was able to reproduce this issue after updating the Xamarin.GooglePayServices packages. I am attaching a repro project.

The app crashes at launch with

> System.TypeLoadException: Could not load type of field 'Xamarin.Forms.Platform.Android.AppLinks.AndroidAppLinks:_client' (0) due to: Could not resolve type with token 01000013 (from typeref, class/assembly Android.Gms.Common.Apis.GoogleApiClient, Xamarin.GooglePlayServices.Basement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) assembly:Xamarin.GooglePlayServices.Basement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null type:Android.Gms.Common.Apis.GoogleApiClient member:<none>
> at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x0001b] in <3fd174ff54b146228c505f23cf75ce71>:0 
> at System.Reflection.MonoCMethod.DoInvoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0007a] in <3fd174ff54b146228c505f23cf75ce71>:0 
> at System.Reflection.MonoCMethod.Invoke (System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 
> at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) [0x00213] in <3fd174ff54b146228c505f23cf75ce71>:0 
> at System.Activator.CreateInstance (System.Type type, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes) [0x000a1] in <3fd174ff54b146228c505f23cf75ce71>:0 
> at System.Activator.CreateInstance (System.Type type, System.Object[] args, System.Object[] activationAttributes) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 
> at Xamarin.Forms.Platform.Android.AndroidAppIndexProvider..ctor (Android.Content.Context context) [0x0003f] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AndroidAppIndexProvider.cs:21 
> at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.LoadApplication (Xamarin.Forms.Application application) [0x00147] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:127 
> at App1.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00027] in C:\Users\jigarrid\Documents\_Bugs\54383 applinks\App1\App1\App1.Android\MainActivity.cs:25 
> at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <6296d3d76c5d4378959a1d9bf7205023>:0 
> at (wrapper dynamic-method) System.Object:191d2981-ba6d-4787-8ff4-b2adf9cbec09 (intptr,intptr,intptr)


As the exception indicates, the crash is happening because the GoogleApiClient type cannot be resolved in the Xamarin.GooglePlayServices.Basement assembly. This is because in versions after 29.0, the GoogleApiClient type was moved to the Xamarin.GooglePlayServices.Base assembly instead. However, the Forms.AppLinks package is built with the older v29.0 packages so it attempts to load the type from the old assembly.

The simple workaround is to _not_ update the GPS packages. However if you do need to update the packages, you could fork the Xamarin.Forms source and build the AppLinks project with updated GPS packages yourself and use those assemblies. However I cannot guarantee right now that this won't present other issues.

In the meantime, I will also confirm this report so the engineers are aware of this issue. Thanks!
Comment 6 Jimmy [MSFT] 2017-06-06 16:13:59 UTC
Created attachment 22720 [details]
repro project
Comment 7 Brandon Minnick 2017-07-02 19:11:36 UTC
FYI - this bug prevents Xamarin.Forms users from using Xamarin.Forms AppLinks and the Mobile Center Push SDK in the same Xamarin.Android project.

If a File -> New Blank Xamarin.Forms app is created, the Xamarin.Forms App Links NuGet Package is added and the Mobile Center Push NuGet Package is added, the Android app will crash at run-time.

I put together a reproduction app here.
https://github.com/brminnick/XamarinForms-MobileCenterPush-AppLinks-Repro

Crash Report:
Could not load type of field 'Xamarin.Forms.Platform.Android.AppLinks.AndroidAppLinks:_client' (0) due to: Could not resolve type with token 01000013 (from typeref, class/assembly Android.Gms.Common.Apis.GoogleApiClient, Xamarin.GooglePlayServices.Basement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) assembly:Xamarin.GooglePlayServices.Basement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null type:Android.Gms.Common.Apis.GoogleApiClient member:<none>
Comment 8 Guillaume Perrot 2017-07-05 19:17:43 UTC
Hi, since Mobile Center SDK is compatible with the latest version of those Google packages, the bug should be on Xamarin App Links side to fix as they are not compatible with latest packages and they should.

Mobile Center should not downgrade as people would have issue with updating those dependent packages.
Comment 9 Samantha Houts 2017-07-06 23:29:36 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1037
Comment 10 Pablo Biagioli 2017-07-07 15:52:15 UTC
Hi, I tested the pull request and it worked fine with my Xamarin.Forms Android project.
There's an additional step to make the whole approach work and it's to fully integrate Firebase into your MainActivity.cs

You need to put these 2 lines to initialize AppLinks correctly:
Firebase.FirebaseApp.InitializeApp(this);
AndroidAppLinks.Init (this);

From Firebase's side, you need to download google-services.json file and place it in the root of your Android project, and finally choose the GoogleServicesJson option in BuildAction's menu (right clicking the file).

Cheers
Pablo
Comment 11 Pablo Biagioli 2017-07-07 19:04:26 UTC
Hi Samantha, Jimmy,

I would like to know what are the next steps. I'm really interested in having this issue solved because my project is depending on Deep linking, and this feature is something that, when it breaks, it breaks the whole app because it goes integrated in the MainActivity.

Can someone give me some time estimates on when am I going to get a code review so we can move forward?

I would really love to work with you guys in fixing this issue ASAP.

Cheers
Pablo
Comment 12 Drew Peterson 2017-07-24 14:53:08 UTC
Building on what I said in a comment on the PR, if there's anything the community can do to move this along please let us know. We cannot move forward with remote notifications in our app until this is resolved, would someone from the Xamarin side be able to acknowledge that they're at least aware of the PR that Pablo has submitted?

Thanks,
Drew
Comment 13 Samantha Houts 2017-10-04 00:30:56 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1107

Note You need to log in before you can comment on or make changes to this bug.