Xamarin Forms cross-platform map issue on Android - xamarin.android

After upgrading Xamarin Forms and Maps to version 2.3.3.193, on my Android app, I now receive the following error when I attempt to display a map:
{Xamarin.Forms.Platform.Android.ViewRenderer}
{System.MissingMemberException}
Android.Gms.Maps.MapView.get_Map' not found
Any idea what is going on? It worked before the update. Any assistance would be appreciated.
Screen shots of my Nuget manager showing 2.3.3.193 as latest stable version.

Xamarin.Forms.Maps 2.3.3.193 requires Xamarin.GooglePlayServices.Maps version to be 29.0.0.1. Not 29.0.0.1 or higher!
Dependencies
From your screenshot, you have 42.1001.0
I'm in the same boat. Still got to use the nuget package built in march 2016!

Update
The issue is fixed in the latest stable version of Xamarin Forms 2.3.4.224.
Original Answer
Refer to https://bugzilla.xamarin.com/show_bug.cgi?id=52625 for discussion about this issue.
Google removed their java getMap method which had been obsoleted for some time (even in 29.0.0.1 you can see the equivalent Map property is marked obsolete). The Forms renderer uses the Map property (so the underlying java getMap method), which no longer exists in newer versions of play services, so crash occurs. The Forms renderer will need to change to use the GetMapAsync method.
Rob Lyndon (Bugzilla discussion) created the patch you could use: https://www.nuget.org/packages/XamarinForms.Maps.Android.TemporaryPatch
I couldn't use the patch directly from Nuget due to PCL profile missmatch, so I ended up doing the following:
Copy MapRenderer from the patch to your Android project. Make sure to adjust namespace
Extend Map in your PCL project
public class CustomMap : Xamarin.Forms.Maps.Map { }
Create custom renderer in Android project
[assembly: ExportRenderer(typeof(CustomMap), typeof(MapRenderer))]
namespace StanleySteemer.Nimbus.Mobile.Renderers
{
public class CustomMapRenderer : MapRenderer {}
}
Use CustomMap instead of Map in your View

Related

"MapView not found in Esri.ArcGISRuntime.Xamarin.Forms" error Xamarin Forms iOS

I am using ArcGIS Runtime 100.4.0 in my Xamarin forms solution which is consist of
Android Project
iOS
.Net Standard 2 project (shared logic used by android and ios)
My code is very simple and it only tries to display a map. I used the code from Esri example for displaying a map and I already have it working in another project where the app logic is in a Visual Studio Shared Project (instead of .net standard). The Esri sample project also uses Visual Studio Shared Project. I think the issue that I am facing can be resolved by using Visual Studio Shared Project but for some technical reasons I have to use .Net Standard for my shared logic.
Now here is the issue:
The android app shows the map without an issue, however in my iOS app, I get the following error in my .net standard project when the app tries to initialize the map:
MapView not found in xmlns clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms
I am confident that I have all right references in my iOS project and also the fact is the error happens in the .net standard project which is working in my Android app.
How is it possible to be missing MapView class when using my .netstandard project in iOS but not android?
While I was investigating this I found a solution which I have no clue about the reason:
I added a line before InitializeComponent() in my page code behind which simply creates an instance of Esri.ArcGISRuntime.Xamarin.Forms.MapView, and that fixed it:
public MapPage()
{
var a = new Esri.ArcGISRuntime.Xamarin.Forms.MapView();
InitializeComponent();
}
If I remove that line I get the error again in iOS. I have no idea why that happens

Reference to type 'System.IConvertible' claims it is defined in assembly mscorlib

Anytime I try to reference an NUNIT data type in the iOS framework, I am given a compiler error saying it can't find the IConvertible type
Error CS7069: Reference to type System.IConvertible' claims it is defined assemblymscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089', but it could not be found (CS7069) (logic)
I was able to reproduce this by creating a brand new Xamarin.Forms project that only targets iOS.
Immediately after creating it, I added a second Xamarin.Forms project, this time a PCL.
I then needed to add the Xamarin.iOS library so that I can reference the iOS specific APIs, specifically the Photos API. I did this by navigating to
~/Library/Frameworks/Xamarin.iOS.framework/Versions/9.0.1.29/lib/mono/Xamarin.iOS/Xamarin.iOS.dll
Lastly, I added a blank class to the new PCL project, and created a locally scoped NUNIT field. This is where the compiler error happens. This happens in my current project when I try to get the number of photos in a PHAssetCollection, as that is an NUNIT data type.
using System;
namespace logic
{
public class EmptyClass
{
public EmptyClass()
{
nuint test = 5;
}
}
}
This gives me the compiler error I've referenced above. How can I solve this? This has become a blocking issue for me, am I referencing the wrong Xamarin.iOS.dll? It's not available in the list of nuget packages when I scan for them, so I can't add it via NuGet. NuGet only has Xamarin.Forms.dll available.
Update 1
After trying a few different combinations, I think that I have a working solution. Instead of creating a Xamarin.Forms Library, I created a normal iOS PCL library instead. This solved that problem.
I don't know why the Xamarin.Forms library wouldn't work. Is it not intended to be used for platform specific code?
Xamarin Forms PCL's need to be platform agnostic. If you have a NUnit project that needs access to a Xamarin.iOS specific reference, then you need to build within the iOS project / iOS PCL.
Xamarin.iOS.dll can only be referenced from a iOS related project.

how to use protobuf-net in the xamarin ios pcl

I am trying to use protobuf-net with the new xamarin ios pcl, and it's nuget packet doesn't appear to support the framework. Is there a way to import protobuf-net into the pcl?
Update:
I just found recompiling the PCL with the new Xamarin PCL definitions allowed the resulting library to be references. Nice work! Let me know when a new version is posted to Nuget.
The NuGet package includes PCL drops, but it is unclear to me what change you would have me make to the NuGet package here, as there is no specific "Xamarin" target that I know of; the example targets are described here; protobuf-net currently includes a broad target of portable-sl4+net40+wp7+windows8. If you know of a target (or indeed a PCL build combination) that works for Xamarin for iOS, please let me know.
I should also note that the NuGet drop is the "Full" implementation, where meta-programming is performed at runtime. Because of the limitations in iOS, you may find you get better performance by using the "CoreOnly" implementation combined with the "precompile" tool, available from the google-code drop. This is described here.
I was able to use NuGet version of protobuf-net by manually editing the .csproj file for my portable library and setting the target framework profile to match protobuf-net:
<TargetFrameworkProfile>Profile136</TargetFrameworkProfile>
The resulting portable library worked well with Xamarin.Android. According to this list, it should work with Xamarin.iOS as well.

Is there any class in MvvmCross that inherits from ActionBarActivity?

I'm developing an App with Xamarin.Android (aka MonoDroid), using the great MvvmCross Framework. The application uses Fragments, and need an ActionBar.
I've noticed that the MvxFragmentActivity inherits from MvxEventSourceFragmentActivity, and this last inherits from FragmentActivity, which has no ActionBar support. To support ActionBar, i need a class that inherits from ActionBarActivity, wich is included in the Support Library, and inherits from FragmentActivity.
So, my question is: Is there any MvvmCross class that Inherits from ActionBarActivity?
If not,
Can I just create a MvxEventSourceActionBarActivity and a MvxActionBarActivity that inherits from the first one, with just the same code of the MvxEventSourceFragmentActivity and MvxFragmentActivity just changing the inherits?
The basic answer is "No. There's no existing class. But I f you want to add binding to any Activity, then you can do so using 2 layers of inheritance - adding first an eventsource and then an Mvx layer"
There is a bit more detail about this in a few questions - eg ActionBarSherlock with latest MVVMCross
For the latest android support library, there is one issue to be aware of currently - when building binaries you currently either have to choose the mono library which gives you compatibility with play services or you have to choose the new Xamarin component which gives you the latest support lib - see MvvmCross - trying to use Fragments AND latest support lib results in linking problems and https://bugzilla.xamarin.com/show_bug.cgi?id=15205

Json.NET under Unity3d for iOS

has anyone succeeded to adapt/port Json.NET to a version able to run under Unity3d deployed to iOS (and the webplayer, and android, too, but these seem less problematic), somehow overcoming the AOT issues there?
Or are there plans to release a compatible version of Json.NET?
Many thanks,
Max
You can use netstandard version of Newtonsoft.Json in Unity and it works fine. It seams that this library has changed some inner implementations to not use System.Reflection.Emit for deserialization anymore.
Just be sure that after downloading nuget package you get Newtonsoft.Json.dll from netstandard2.0 folder, not from net45. And also don't forget to specify in link.xml that System.Linq.Expressions.Interpreter.LightLambda class shouldn't be stripped (it's used for deserialization) along with libraries/classes that you use for deserialization (to preserve constructors). Your link.xml should look smth like this:
<linker>
<assembly fullname="Your.Dto.Package.Name" preserve="all" />
<assembly fullname="System.Core">
<type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
</assembly>
</linker>
We use this library in all our projects for Android and iOS with IL2CPP and Mono runtimes.
Moreover, unlike Unity's JsonUtility, Newtonsoft.Json fully supports any type of objects, including Dictionary.
Microsoft Example
Newtonsoft Json fails AOT in iOS and also fails at deserializing anything inheriting from KeyedCollection in the webplayer. Here's a version that has been fixed:
JSON .NET For Unity (Supports iOS)
We use MiniJson and so far it serves our json needs well :)
I have been facing the same issue for a while and searched on every nook and cranny of the internet to look for a solution. Here's what worked for me.
I replaced NewtonSoft.Json with NewtonSoft.Json for Unity
Uninstalled NewtonSoft.Json from Unity's Nuget package manager.
Install NewtonSoft.Json for Unity with Unity's package manager. Follow this installation steps
What's the difference?
NewtonSoft.Json for Unity is different from standard NewtonSoft.Json
NewtonSoft.Json does not support AOT targets for IL2CPP builds in Unity
NewtonSoft.Json for Unity supports AOT targets such as all IL2CPP builds (WebGL, iOS, Android, Windows, Mac OS X) and portable .NET (UWP, WP8).
Hope this helps. Cheers!
Nope AFAIK.
LitJson and JsonFX would be alternate choice for Unity3D.
http://wiki.unity3d.com/index.php?title=UnityLitJSON
Have a look at the modified version of LitJson: UnityLitJson
Actually LitJson has some issues and is not always working as expected, so I created a simple JSON-Lib that can handle all Unity3D Types, Enums and arbitrary classes. Find it at GitHub: Tiny-JSON
You can use it very simple:
// encode
Animal a = new Animal(4);
string json = Json.Encode(a);
// decode
IList<Animal> a = Json.Decode<IList<Animal>>("[{\"legs\":4}, {\"legs\":2}]");
Yes, we share code on client and server and use an older version when it was called NewtonSoft.Json. Works in IOS, Android, everything.
Search for NewtonSoft.Json, and you could probably find an archive.

Resources