5

I'm attempting to integrate the Localytics SDK (via their Xamarin component) into my Xamarin Android app. It compiles in Debug mode, however if I switch to a Release build then it errors on compile:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Error executing task LinkAssemblies: error XA2006: Could not resolve reference to 'Android.Gms.Gcm.Iid.InstanceIDListenerService' (defined in assembly 'LocalyticsXamarin.Android, Version=4.2.0.29760, Culture=neutral, PublicKeyToken=null') with scope 'Xamarin.GooglePlayServices.Gcm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. When the scope is different from the defining assembly, it usually means that the type is forwarded. (com.rpr.mobile.droid)

If I switch the Linker Behavior from Link SDK assemblies only to Don't link then it compiles fine, however this isn't an option because then the apk is too large. If I switch back to Link SDK assemblies only and add "LocalyticsXamarin.Android" to the Ignore assemblies list, it still gives the same compile error.

This error seems to imply a versioning mismatch in Google Play Services between my app and the Localytics Xamarin wrapper, however they sent me an updated version of their wrapper that uses the latest version (42.1001.0) and I've confirmed that it matches with our app. Furthermore, their own sample Android project compiles fine. I've combed through every setting in their sample Android project and changed it to match mine, and still theirs compiles and mine doesn't.

Here is packages.config in my Android project:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="modernhttpclient" version="2.4.2" targetFramework="MonoAndroid60" />
  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="MonoAndroid60" />
  <package id="Rx-Core" version="2.2.5" targetFramework="monoandroid70" />
  <package id="Rx-Interfaces" version="2.2.5" targetFramework="monoandroid70" />
  <package id="Rx-Linq" version="2.2.5" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="25.1.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Compat" version="25.1.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Core.UI" version="25.1.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Core.Utils" version="25.1.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Fragment" version="25.1.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Media.Compat" version="25.1.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.v13" version="25.1.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.v4" version="25.1.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="25.1.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="25.1.1" targetFramework="monoandroid70" />
  <package id="Xamarin.Build.Download" version="0.4.3" targetFramework="monoandroid70" />
  <package id="Xamarin.Firebase.Analytics" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.Firebase.Analytics.Impl" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.Firebase.Common" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.Firebase.Iid" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Analytics" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Analytics.Impl" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Base" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Basement" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Gcm" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Iid" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Location" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Maps" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.TagManager.V4.Impl" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Tasks" version="42.1001.0" targetFramework="monoandroid70" />
</packages>

And here is packages.config for the sample Localytics project that works:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Xamarin.Android.Support.Compat" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.Core.UI" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.Core.Utils" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.Design" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.Fragment" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.Media.Compat" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.Transition" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.v4" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.v7.AppCompat" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.v7.CardView" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.v7.MediaRouter" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.v7.Palette" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.v7.RecyclerView" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Android.Support.Vector.Drawable" version="25.1.1" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Build.Download" version="0.4.3" targetFramework="MonoAndroid70" />
  <package id="Xamarin.Forms" version="2.3.3.193" targetFramework="MonoAndroid70" />
  <package id="Xamarin.GooglePlayServices.Base" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Basement" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Clearcut" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Gass" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Gcm" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Iid" version="42.1001.0" targetFramework="monoandroid70" />
  <package id="Xamarin.GooglePlayServices.Tasks" version="42.1001.0" targetFramework="monoandroid70" />
</packages>

To reproduce the issue...

Here is the Localytics SDK Xamarin wrapper latest code, which builds just fine. You'll want to take the .xam file and install it to Xamarin Studio using Xamarin-Component.

Here is a slimmed down version of my Android project code.

I apologize for the size of my project, I removed all of the code and resources but it's still big because of the Components and Packages, which I didn't want to remove since they're relevant to the issue. You'll want to open the RPR Mobile - Android.sln solution, change to Release-Prod, then try to build and you'll see the error.

Any ideas?

Justin
  • 17,670
  • 38
  • 132
  • 201
  • I think there might be a couple of issues going on here. 1. What is your `` of your project? Is it the latest and greatest? If not, it should be. 2. It's implied that this type is being linked out. Can you try link skipping `Xamarin.GooglePlayServices.Iid` as that's the actual assembly this lives. For help investigating, can you please add a `packages.config` / any other libraries and their versions so it's easier to see what is all going into your project? If you can make a sample app with the same libraries and upload, that would help as well! – Jon Douglas Apr 10 '17 at 15:37
  • @JonDouglas The target version is Android 7.1 (API level 25). I just tried link skipping Xamarin.GooglePlayServices.Iid and it still gave the same error. Let me update the question with packages.config... – Justin Apr 10 '17 at 15:52
  • In the error message, when does it say Xamarin.GooglePlayServices.Gcm, Version=1.0.0.0, when both are using Gcm version 42.1001.0? Is it just a bad error message or could this be the cause? – Justin Apr 10 '17 at 16:06
  • I don't have anything to go off of other than the Github link above for Localytics. It seems the `packages.config` differs there: https://github.com/localytics/localytics-xamarin/blob/master/LocalyticsXamarin/Android/packages.config and https://github.com/localytics/localytics-xamarin/tree/master/LocalyticsXamarin/packages Is there a link to get this sample you are referring to? – Jon Douglas Apr 10 '17 at 16:14
  • @JonDouglas - Yeah their github repo still references the old Google Play Services. We thought the issue was that they needed to update their wrapper to leverage the latest Google Play Services, so they sent us an updated version but it gives the same error. Their sample project in that updated code compiles fine, so I'm not sure that would help for you to run that. It sounds like I need to slim down my project and then upload that for you to test out. Let me work on that today... – Justin Apr 10 '17 at 16:26
  • Yeah that would be best to help investigate here. I'm pretty much in the dark without seeing what the sample project is doing. Thanks! – Jon Douglas Apr 10 '17 at 16:30
  • @JonDouglas - Code and repro steps added, let me know what you find. And thanks for the assistance, we've been blocked on this issue for months! Actually, the code is still copying up to Dropbox, I'll update this thread once it's complete... – Justin Apr 10 '17 at 18:42
  • Hmm the component attached to this solution does not have a `.dll` that references `Xamarin.GooglePlayServices.Iid`. Whereas the component download `.dll` does indeed have a reference to it: https://www.screencast.com/t/O55I6a7SV (Top is the component download source, Bottom is the component inside your project) – Jon Douglas Apr 10 '17 at 20:58
  • If you look at the bottom component, it still says it's platform is `MonoAndroid v4.0.3`. However I would say that they messed something up with their "patch" because the `PATCH` version number is higher as well. – Jon Douglas Apr 10 '17 at 21:04
  • @JonDouglas - The zips have been uploaded now, I had to use Box instead of Dropbox due to size restrictions. How did you get to the view within that screencast? I'm not seeing the MonoAndroid v4.0.3 or the old patch number anywhere. – Justin Apr 10 '17 at 21:47
  • Using `dotPeek` on the items you uploaded on the `LocalyticsXamarin.Android` dll in both the items you uploaded. – Jon Douglas Apr 10 '17 at 21:49
  • That looks to be Windows only, I'm on OSX so can't try it. In any case, I'm not sure how the LocalyticsXamarin.Android reference could be different in the two solutions, as I'm adding them the exact same way. I did a make / rake on the Localytics component, then used Xamarin-Component.exe to install it to Xamarin Studio. Then within both the Localytics demo project and within my own, I did Components > Edit Components and chose Add to Project for the Localytics SDK under Installed on this machine. – Justin Apr 10 '17 at 21:56
  • You should be able to "look" at that component by going into the folder and looking at the `lib` that's installed. In my case it was old targets although the version number was new. This seems more like a vendor issue at this point. – Jon Douglas Apr 10 '17 at 22:07
  • You got me on the right track... The fact that the sample project and mine had different versions of the Localytics component led me to try bumping the version of the component, doing a make clean / make / rake, installing the new .xam file using xamarin-component.exe, then referencing this in our project. This worked, which means that either the .xam file they sent me was no good, or xamarin-component.exe has issues with overwriting a component with the same version number. In any case, thanks for your help. If you want to post your suggestions as an answer, I'll accept it. – Justin Apr 10 '17 at 22:33

1 Answers1

5

The component that ships with this PATCHED version does not seem to be updated to include the references you need such as Xamarin.GooglePlayServices.Iid.

You will need to most likely remake this component or have the vendor do so for you. It seems like there's a caching issue here with regards to what final .dll is being added to your project.

Jon Douglas
  • 13,006
  • 4
  • 38
  • 51