urbanairship/urbanairship-xamarin

Xamarin Forms Compatibility

Closed this issue · 36 comments

So just a heads up, the xamarin android support packages and xamarin forms packages have a version dependency and due to this Xamarin Forms projects are still on the 2.3.0 versions of the support library packages. This makes the new version of these bindings incompatible with forms projects. Just thought i'd give you a heads up.

+1 blocking integration of Urban Airship with a Xamarin Forms app.

Version 2.2.1 of the NuGet package is the latest with Xamarin Forms Compatibility.

@JaridKG and @edandersen Looking into it. Our SDK uses a few APIs in newer versions but Ill see what 2.3.0 equates to. Thanks for reporting this.

No problem, there is an upcoming forms release that may fix this issue but at the moment it is blocking because I can't pull in the android fragment support nuget

@JaridKG Do you have a ticket number of forum post you can link me to about the xamarin forms update? We are trying to develop a PCL for the component and it would be awesome if it was actually able to be used in forms

I cant find it now sorry. However checking out the package dependencies https://www.nuget.org/packages/Xamarin.Forms/2.3.4.192-pre2 it appears users building MonoAndroid7 android apps will be able to update the android packages as necessary, not being bound to a specific version

@JaridKG Thank you! It looks like it should be ok. We will try testing the PRE version to verify it works fine and if not we will try to contact Xamarin for help.

Looks like https://www.nuget.org/packages/Xamarin.Forms/2.3.3.193 might of fixed the issue. Closing for now but please open if it still is causing conflicts.

I am having this issue as well. I cannot update the support libraries as I have other things in my Xamarin Forms Android project that relay on the 23.3.0 support libraries. (Which rules out using android 7.0 with the prerelease) I started a support request with Urban Airship on a solution. Any suggestions as I need to get android push notifications setup asap.

I have tried to use version 2.2.1 of the urban airship library but I get these warnings below in the log and nothing happens when I send the notification. If you think a more in depth explanation would be useful I can send you want I sent support.

AndroidManifest.xml missing required service: com.urbanairship.analytics.EventService
AndroidManifest.xml missing required receiver: com.urbanairship.push.GcmPushReceiver

I googled these errors and one solution was to add them to the manifest but this does not seem to work. So not sure how to fix this. Any ideas?

Also is there a sample project that uses xamarin forms android project and the newest urban airship sdk and portable library that actually works?

I tried ot make a new xamarin forms project and put the newest sdk in it with android 7.0 and the newest support libraries but I am getting all kinds of weird compile errors. Is this just me?

Thanks,
Bob

P.S iOS works great btw, it is just this support library issue. What is really funny tho is the portable library claims to work really well with xamarin forms yet you cannot install it on any xamarin forms stable versions since it requires urban airship 4.2+ and that requires the newer support libraries.

@Bobisback What version of Xamarin forms are you trying to use? Whats your min android SDK version set to? It appears to be fixed with https://www.nuget.org/packages/Xamarin.Forms/2.3.3.193 but only for MonoDroid7.

I have the latest version of Xamarin forms, 2.3.3.193. I am compiling agaist 7.0, and my target sdk is 7.0. But I have other dependancies on the android support library that provide core functionality in my project, including maps, permissions, and some other things. If i try to update I get all kinds of dependency errors. I will post the log. So I am not sure I can just update the support library.

Is it possible to get a stripped down version of the urban airship sdk that only compiles against the 23.3.0 support library? Would it be possible for me to try and download the current sdk and give it a shot?

The issue is that even though xamarin forms supports it nothing else that depends on xamarin forms supports it. So I either loss core functionality and get notifications, or I leave out the notifications and keep my core functionality.

Attempting to gather dependency information for package 'urbanairship.4.2.2' with respect to project 'CitizensConnectMobileApp.Platform.Android', targeting 'MonoAndroid,Version=v6.0'
Attempting to resolve dependencies for package 'urbanairship.4.2.2' with DependencyBehavior 'Lowest'
Unable to find a version of 'Xamarin.Android.Support.v4' that is compatible with 'Plugin.Permissions 1.1.7 constraint: Xamarin.Android.Support.v4 (>= 23.0.1.3)', 'urbanairship 4.2.2 constraint: Xamarin.Android.Support.v4 (>= 24.2.1)', 'Xamarin.Android.Support.Animated.Vector.Drawable 23.3.0 constraint: Xamarin.Android.Support.v4 (= 23.3.0)', 'Xamarin.Android.Support.Design 23.3.0 constraint: Xamarin.Android.Support.v4 (= 23.3.0)', 'Xamarin.Android.Support.v7.AppCompat 23.3.0 constraint: Xamarin.Android.Support.v4 (= 23.3.0)', 'Xamarin.Android.Support.v7.MediaRouter 23.3.0 constraint: Xamarin.Android.Support.v4 (= 23.3.0)', 'Xamarin.Android.Support.v7.RecyclerView 23.3.0 constraint: Xamarin.Android.Support.v4 (= 23.3.0)', 'Xamarin.Android.Support.Vector.Drawable 23.3.0 constraint: Xamarin.Android.Support.v4 (= 23.3.0)', 'Xamarin.Forms 2.3.3.193 constraint: Xamarin.Android.Support.v4 (= 23.3.0)', 'Xamarin.GooglePlayServices.Base 29.0.0.1 constraint: Xamarin.Android.Support.v4 (>= 23.1.1.1)', 'Xamarin.GooglePlayServices.Basement 29.0.0.1 constraint: Xamarin.Android.Support.v4 (>= 23.1.1.1)', 'Xamarin.GooglePlayServices.Maps 29.0.0.1 constraint: Xamarin.Android.Support.v4 (>= 23.1.1.1)', 'Xamarin.GooglePlayServices.Measurement 29.0.0.2 constraint: Xamarin.Android.Support.v4 (>= 23.1.1.1)'.
========== Finished ==========

Not to mention I just tried to create a new xamarin forms project and add the sdk and I was still getting compiling errors. Do you guys have a Xamarin Forms sample with your sdk in it that works?

@Bobisback The dependency issues you posted above can be resolved by updated your support libraries. Those seem to be the only ones that are requiring a specific version. The rest are >=.

Support libraries are generally backwards compatible so you should not have any issues with updating them. It is also best practice to match the support library version with compileSdkVersion. Your current compileSDKVersion is 25, so I would recommend that you update your support libraries.

We currently do not have a xamarin forms sample that I can share. I created a quick xamarin forms project, added the UA SDK and portable library and had 0 build issues. Could you post your output for the new forms sample you created?

I am trying to update my support libraries right now, I am just getting dependency error after dependency error. Most of them read similar to this:

Attempting to gather dependency information for package 'Xamarin.GooglePlayServices.Base.32.961.0' with respect to project 'CitizensConnectMobileApp.Platform.Android', targeting 'MonoAndroid,Version=v7.0'
Attempting to resolve dependencies for package 'Xamarin.GooglePlayServices.Base.32.961.0' with DependencyBehavior 'Lowest'
Unable to find a version of 'Xamarin.Android.Support.Compat' that is compatible with 'Xamarin.Android.Support.Core.UI 24.2.1 constraint: Xamarin.Android.Support.Compat (= 24.2.1)', 'Xamarin.Android.Support.Core.Utils 24.2.1 constraint: Xamarin.Android.Support.Compat (= 24.2.1)', 'Xamarin.Android.Support.Design 24.2.1 constraint: Xamarin.Android.Support.Compat (= 24.2.1)', 'Xamarin.Android.Support.Fragment 24.2.1 constraint: Xamarin.Android.Support.Compat (= 24.2.1)', 'Xamarin.Android.Support.Media.Compat 24.2.1 constraint: Xamarin.Android.Support.Compat (= 24.2.1)', 'Xamarin.Android.Support.Transition 25.1.1 constraint: Xamarin.Android.Support.Compat (= 25.1.1)', 'Xamarin.Android.Support.v4 25.1.1 constraint: Xamarin.Android.Support.Compat (= 25.1.1)', 'Xamarin.Android.Support.v7.AppCompat 24.2.1 constraint: Xamarin.Android.Support.Compat (= 24.2.1)', 'Xamarin.Android.Support.v7.Palette 24.2.1 constraint: Xamarin.Android.Support.Compat (= 24.2.1)', 'Xamarin.Android.Support.v7.RecyclerView 24.2.1 constraint: Xamarin.Android.Support.Compat (= 24.2.1)', 'Xamarin.Android.Support.Vector.Drawable 24.2.1 constraint: Xamarin.Android.Support.Compat (= 24.2.1)'.
========== Finished ==========

So what I am going to do is delete all packages and remove all references and then try to systematically add everything back in. Maybe this will fix it.

Would you recommend updating to the very latest or just what the current sdk needs?

@Bobisback In v24 of the support library they broke everything out into different modules, so I can definitely see the upgrade packages thing stumbling.

I would upgrade to the latest if you can. I am not sure about any known issues, but they tend to make bug fixes every release - https://developer.android.com/topic/libraries/support-library/revisions.html

Ok, I will post back with results. I am reinstalling everything now. Honestly it is probably just some dust clogging up visual studio, I started this project back in forms version 1.4 so hahaha.

@rlepinski Well this is a problem. So I use HttpClient throughout the application. Not being able to use it on android would be a huge issue. Any suggestions?

Attempting to gather dependency information for package 'Microsoft.Net.Http.2.2.29' with respect to project 'CitizensConnectMobileApp.Platform.Android', targeting 'MonoAndroid,Version=v7.0'
Attempting to resolve dependencies for package 'Microsoft.Net.Http.2.2.29' with DependencyBehavior 'Lowest'
Resolving actions to install package 'Microsoft.Net.Http.2.2.29'
Resolved actions to install package 'Microsoft.Net.Http.2.2.29'
Install failed. Rolling back...
Package 'Microsoft.Bcl.Build.1.0.14' does not exist in project 'CitizensConnectMobileApp.Platform.Android'
Could not install package 'Microsoft.Bcl.Build 1.0.14'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
========== Finished ==========

Never-mind, got it figured out. For reference: https://bugzilla.xamarin.com/show_bug.cgi?id=43070

"More recent versions of NuGet 2.12, 3.4 and 3.5 all fail to install Microsoft.Bcl.Build 1.0.14 into an Android project for some reason.

Xamarin Studio 6.0.1 which uses NuGet 2.8.7 works fine. This also affects Visual Studio so it looks like a change in NuGet has caused a problem.

Xamarin Studio 6.0.2 which uses NuGet 2.12 fails.
Xamarin Studio 6.1 which uses NuGet 3.4.3 fails.
Visual Studio 2015 with the latest beta of NuGet 3.5 also fails.

A workaround is to install the latest Microsoft.Bcl.Build 1.0.21 NuGet package first before installing Microsoft.Net.Http."

@Bobisback Yep, I was just reading that bug report. Glad you figured it out.

@rlepinski So I completely reinstalled everything. Now I am getting 200+ errors related to xamarin android and Xamarin forms missing. They are installed via nuget. I searched google with no luck. Any ideas? I tried clearing the resharper cache. Restarting the computer, restarting visual studio, double checking that I have all the 7.0 apis from teh android sdk manager. What else could cause the xamarin forms from building?

I fixed it by manually adding references to Mono.Android, Mono.Android.Export and some mcslib or something. I found this by comparing project files to see what was missing from the references list.

Now i just have 11 errors related to custom renderer. Something about needing to reference System.ObjectModel. But that is not in my references before.

So I fixed everything by creating a new xamarin forms project. Then editing the android project file to find the missing references and moving these references into my android project file. Magic, no more errors!

<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ObjectModel" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />

Now I am getting a '"java.exe" exited with code 2' error, which means to many refrences. i am guessing it is from updating the google play services. Just not sure how to strip out the extra references. Muti-dexing gives me a error. Proguard gives me a error. Now sure what to do next.

Ok so I solved it with mutidex, which apparently uses proguard as I had to install the updated 7.0 pro-guard package. I also had to move my android sdk to a path that has no spaces or special characters. Otherwise it would error lol. Stupid Android.

I am now getting notifications :D

Thanks for all the help.

Awesome, glad you got it working.

Are you pulling in the full google play services or individual modules? If the former you might be able to reduce your method count under the dex limit.

I think i am only pulling in the modules, the name of the package is not "all" so. But I am also using maps and based on my googling it references alot of google play services.

On another note my debugging stopped working now :( someerror about the debugger is broken and to repair or reinstall it hahaha if it is not one thing it is another.

Here are all the packages I am referencing for google play services. I looked through them and all the stuff I have installed have hard dependancies on each one so. Guessing I do not have much choice.

<package id="Xamarin.GooglePlayServices.Analytics" version="32.961.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Analytics.Impl" version="32.961.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Base" version="32.961.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Basement" version="32.961.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Gcm" version="32.961.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Iid" version="32.961.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Location" version="32.961.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Maps" version="32.961.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Tasks" version="32.961.0" targetFramework="monoandroid70" />

Though I wonder which is better, mutidexing or trying to use pro guard to strip away used code.

@Bobisback Usually you would only use pro guard for a release build, so it probably wont work great for development. You most likely are stuck with multidex for the time unless you are willing to remove some dependencies. Here is the Android doc on multidex - https://developer.android.com/studio/build/multidex.html. I do not have any experience using it with Xamarin.

Ya I noticed that proguard was not working with dev. So mutidexing it is. No big deal lol. As long as people know that compile my project to make sure the android sdk has no spaces or special characters in the path. Otherwise they will get some super weird errors lol. I am just happy it is working and so is my employer. If it cost me debugging in android so be it hahaha (I am repairing visual studio now... fingers crossed).

Either way thanks for all the help, you were much more helpful then urban airship support.

So just for completeness and then i will stop spamming this thread. Turns out when I was fumbling around with the android project settings I accidentally changed the "debugger" settings to c++, changing it back to .Net (Xamarin) made it work great. hahahah

And now my push notifications do not work again, man I hate android.....

@Bobisback, lets open up a new issue if you are having issues. Will need verbose logs. Try to prevent posting any secrets/keys.

I am not sure, it is working again. I do not know what the hell is going on with it. Sometimes I get the message sometimes I don't. iOS gets it every time though. It would seem if I send a test message it works? Maybe? But if I do a actual message it doesn't work. But if I do a test message then a actual message it works.... idk hahahaha

Edit: Now the test messages are not even working hahaa I will create a new issue

With android I've noticed you have to completely uninstall the app and reinstall it if you are debugging to that device. After a couple "debug" sessions the channel ID stops receiving notifications for some reason (pretty sure its an android issue not UA but I don't really know). I just uninstall and reinstall when i'm testing the pushes on android and get a new channel ID. iOS the channel ID never changes and always works

I found a solution if you are using android 7.0

#60