Attempting to add an MQTT library from NuGet into Xamarin project - xamarin

I saw that Xamarin was now free and decided to try writing a mobile app using it instead of what another technology I was playing with. After some various hiccups, I was able to get the new Xamarin Android project to build, deploy and run on the simulator. I then decided to try out MQTT connectivity from it before I went any further. No matter which MQTT library I to install from NuGet, for example the System.Net.Mqtt one from Xamarin, I get the following error:
"Could not install package 'System.Net.Mqtt 0.3.12-pre'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v6.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."
I tried several others with no success. It does the same for the ios and Android projects. I did try changing the Android SDK version to use for compiling, but still had the same result. I also don't understand why it says MonoAndroid since I thought all the Mono references were changed to Xamarin? I'm using Visual Studio 15 with Update 2. I tried the stable Xamarin version and also tried the latest alpha. I'm not sure what else to try, I'd really to give Xamarin a try for this project. I did some searching and couldn't find anything that appeared to help with this issue.
Thanks in advance for any help.

Use the Package Manager Console. Then, either:
Install the latest version of MQTT library.
Or install first its dependency, RX-Main and then MQTT.
If you still get an error, please share with us the Log that is shown in the PM Console.

Related

Found conflicts between different versions of "System.Numerics.Vectors" in Xamarin Forms 5 project

I'm building a new Xamarin Forms 5 app using VS 2022 17.1.1. Everything in the project appears to be up-to-date.
I've been working on this project for a while and never had this issue. All of a sudden it just appeared today. The last action I took was to install the Plugin.InAppBilling package, thought the package in question is not used by the Plugin.InAppBilling package.
The error is as follows:
All I can see is that the shared project is using System.Numerics.Vectors version 4.5.0 and it seems to be dependency of Xamarin.Essentials which is version 1.7.1 in my project.
However, the version number of System.Numerics.Vectors seems to be 2.0.5.0 in the Android and iOS projects.
I found the GitHub issue here but I'm not seeing any clear resolution to this issue. Even though it appears to be a warning, in my case, I can no longer run the app because I keep getting deployment error to the Android Emulator or actual device. It simply refuses to deploy my app to the device/emulator. So, it's really NOT a warning in my case. It's a show-stopper. I'm a bit surprised about how lightly the Xamarin Essentials folks seem to have taken this issue on GitHub.
Has anyone actually resolved this issue? If so, what's the solution?
BTW, in my case both the Android and the iOS projects are throwing this error/warning and both use System.Numberics.Vectors version 2.0.5.0 even though the shared project has version 4.5.0 installed as a dependency undre Xamarin Esssentials.
I'd appreciate some pointers on how to make this issue disappear. Thanks.
At first, you can try to update the Xamarin.Essentials package in the Android and IOS project with the nuget package manager to the version 1.7.1.
And then, if the error is still here, you can right click the reference and remove the reference of the System.Numberics.Vectors 2.0.5.0 both in your Android and IOS project. Then download the System.Numberics.Vectors 4.5.0 in the nuget package manager both too.

Xamarin Forms on TeamCity: Xamarin.Forms tasks do not match targets

I am building a Xamarin Forms solution (containing an iOS library, an Android library and a .NET Standard library) in TeamCity.
I have just upgraded to Xamarin Forms 3.1.0.583944. The project builds without any problem locally, but on my TeamCity build server (Windows Server 2016), I'm consistently getting the following error:
C:\BuildAgent\work\f12265fda07473c1\src\packages\Xamarin.Forms.3.1.0.583944\build\netstandard2.0\Xamarin.Forms.targets(44,
3): error XF002: Xamarin.Forms tasks do not match targets. Please
ensure that all projects reference the same version of Xamarin.Forms,
and if the error persists, please restart the IDE.
I have tried downgrading Xamarin Forms, and rebooting the build agent. Neither of these has succeeded.
UPDATE: There is a new error:
C:\BuildAgent\temp\buildTmp.nuget\packages\xamarin.forms\3.0.0.561731\build\netstandard2.0\Xamarin.Forms.targets(44, 3): error XF002: Xamarin.Forms tasks do not match targets. Please ensure that all projects reference the same version of Xamarin.Forms, and if the error persists, please restart the IDE.
For some reason, the agent is looking for Version 3.0.0.561731. But that is no longer anywhere in the project. I had deleted the entire C:\BuildAgent\temp\buildTmp\.nuget\packages\xamarin.forms\3.0.0.561731 folder, but it has come back.
ADDENDUM: I notice that every time I upgrade Xamarin.Forms to this version via NuGet, it fails to uninstall the old package, and I have to restart Visual Studio to complete the process. This happens without fail. I am fairly sure this is connected to the breaking build, but that is more due to speculation and experience than concrete analysis.
I found out how to fix the problem, but it's not clear to me why it would manifest in the way it has -- locally and even when I RDP onto the build agent, it builds without trouble, but when I run the build agent from the TeamCity console I hit these compilation errors.
One of my dependencies is a NuGet package, which itself has a dependency on Xamarin Forms. Fortunately, I own that NuGet package, and was able to upgrade its Xamarin Forms version to the latest available package. If I didn't own that package I would be completely stuck though -- so this is only a partial solution.
The above answer was quite helpful for me . I would like to add a couple of additional notes though. I was facing this issue when I was using Xamarin Forms 3+ and my local build was being really inconsistent with the same error "Xamarin.Forms tasks do not match targets. Please ensure that all projects reference the same version of Xamarin.Forms, and if the error persists, please restart the IDE.". Then I cleared my local NuGet cache and rebuilt the project and saw that there were other NuGet package versions being pulled for Xamarin Forms when I did a NuGet restore. I then reversed the ordering of the NuGet packages starting with Xamarin Forms and it all worked fine.

Xamarin Google API client does not exist?

I'm new to Xamarin unfortunately. I've been trying to create a simple page with a map on it using the Xamarin.Forms.Maps package, but upon building I run into about 92 errors all describing that various packages could not be found:
error: package com.google.android.gms.common.api.GoogleApiClient does not exist
error: package com.google.android.gms.common does not exist
error: package com.google.android.gms.maps.GoogleMap does not exist
error: package com.google.android.gms.maps does not exist
error: package com.google.android.gms.tasks does not exist
...and many others. My solution is a Cross-Platform Xamarin.Forms blank mobile app using a .NET class library which I have nothing but the NETStandard.Library, Xamarin.Forms and Xamarin.Forms.Maps packages installed on. I thought that I had set it up correctly according to the official Microsoft documentation, but I still get all these weird errors and searching online for a solution has not been much help. Can someone give me assistance? Let me know if I need to clarify anything.
I had exactly the same issue with the same 92 errors after upgrading my version of Xamarin.Forms to V3.0.0.561731 and installing the latest version of Xamarin.Forms.Maps in Visual Studio Community 2017.
I solved the issue by adding "Google Play Services" via the Android SDK Manager. The item can be found on the "Tools" tab of the Android SDK listed under "Extras".
Note: I had to come out of Visual Studio, and rebuild my solution, and it worked.
Make sure you have installed the nuget on your android project
Xamarin.GooglePlayServices.Base
and
Xamarin.GooglePlayServices.Maps
It's a google maps API requisite.
You can see an entire explanation on official documentation on this link: https://learn.microsoft.com/en-us/xamarin/android/platform/maps-and-location/maps/maps-api#google-maps-api-prerequisites
I had the same error.
For me the solution was to switch to the Visual Studio Preview Channel. I'm now on Version 15.8.0 Preview 2 and the error has gone away.
To get the Preview Channel you can download it here https://www.visualstudio.com/de/vs/preview/
Had this behavior but was because I only included Xamarin.Forms.Maps in PCL project. As soon as I added Xamarin.Forms.Maps also into Android (specially here) and iOS projects all compiled fine.

Xamarin - Updating nuget packages caused errors

I created a "Cross-Platform App (Xamarin.Forms)" app, and i immediately went and update the nuget packages (this is what i was told to do). Then i tried to built it, and not only I got several errors(see bellow) that were about the updated packages, I had code errors as well. I swear the God that i didn't touch the code of the project at all, and here is what I get:
I googled, but i couldn't find out a clean solution for this. I am just one step before quitting this (unprofessional) product, because i cannot run the ready template. Is there someone that can give me a piece of advice for these ridiculous errors ?
Could not install package 'Xamarin.XXXXXXX'. You are trying to install this package into a project that targets 'MonoAndroid,Version=vX.X'
You need to increase your "Compile Target Framework" to at least 7.0 as this error indicates.
You can review the dependancies of a package on the Nuget.org site by looking at the Dependencies section of a particular package:
https://www.nuget.org/packages/Xamarin.Android.Support.v7.AppCompat/
Another SO question/answer example that requires at least MonoDroid 8.0:
https://stackoverflow.com/a/49138485/4984832
Example:
Xamarin.Android.Support.v4 27.0.x.x requires at least MonoAndroid 8.1 to be set as the Compile Target Framework:
You have to use newer android SDK version. You can download the SDK from android SDK manager and then select it from project properties

error : Error initializing task XamlG: Not registered task XamlG

I am developing a Xamarin Forms (PCL) application for IOS and Android Platform.
My Xamarin Studio version is 5.5.4 (Build 15). I am on stable channel.
My Xamarin Forms dll version is 1.3.0.6292.
I have also added a Xamarin Forms Labs reference from NuGet, v1.2.0.
Since yesterday, whenever i am building the solution, i get following error:
error : Error initializing task XamlG: Not registered task XamlG.
Any possible resolution for this error? I have tried clean and build multiple time. Even deleted the entire source code and redownloaded everything from source control but same error.
This error can occur if you have upgraded from an older version of Xamarin.Forms to a newer version. The underlying problem is that the wrong Xamarin.Forms.Build.Tasks.dll is being loaded compared with the one that the custo MSBuild Xamarin.Forms.targets file is expecting.
There is a bug in Xamarin Studio where the old build Xamarin.Forms build tasks are still used after the NuGet package has been upgraded. You can workaround this by closing and re-opening the solution.
However you say you have deleted the source code and downloaded everything again so it sounds like you have a different problem. It may be that your project is trying to use two different versions of Xamarin.Forms at the same time. I would look at your project files (.csproj) in a text editor and make sure they are all using one version of Xamarin.Forms. Check that they are all referencing a single version of Xamarin.Forms.targets and it is the same version.
This is silly.
I just recloned the project in a new fresh folder and build it from scratch and it worked. The more i am using Xamarin Forms, the more buggy and unbaked it seems. There are random issues which get fixed just by rebuilding the project. Or like Matt pointed in his answer below, by just restarting the studio. In my programming experience with different IDEs and platforms, only Xamarin seems to have these problems regularly.

Resources