Use of ArcGIS Runtime SDK .NET in Xamarin app with PCL config ?

3934
15
11-24-2016 12:24 AM
EricDUCOS1
New Contributor III

Hi,

We are working on a new Xamarin project that would include ArcGIS components.

We followed Microsoft recommendation saying that it is better to use the Xamarin model with Portable Library (PCL), not shared components.

But I do not see how to integrate ArcGIS NuGet package in such a project. I get every time  an error saying that I try to to install a package that target .NETPortable but that the package is not compatible with such target...

Please tell me what is the solution...

Probably a version of this Runtime SDK should be supplied supporting PCL ?

Regards.

Eric.

Tags (2)
15 Replies
dotMorten_esri
Esri Notable Contributor

There are no plans to support PCLs. We are hoping to support .NET Standard in the future, but please see my response here regarding that: https://community.esri.com/message/711402-support-for-net-standard#comment-711590

0 Kudos
EricDUCOS1
New Contributor III

Hi everybody,

I am at the origin of this thread and see that I am not alone to request the evolution, but it seems that there is no plan to get ArcGIS component work with standard Xamarin Forms project based on PCL.

But....

With some test and hours, we found an acceptable solution that permit to work with ArcGIS component in such projet. We created a standard XamarinForms PCL project and added a Shared project in which we focused all code using ArcGIS library. And we defined some Interface that permits to the PCL project to get playing with ArcGIS component. In the Shared Library we define some class that implements Interface. And we get the class in the PCL project using Dependency.

For exemple, suppose you have this definition in your XAML page

<ContentView x:Name="_mapContainer" Grid.Row="0"/>

Then you define an interface IMapView

You define a ContentView in your shared project that contains the MapView control of ArcGIS and you make the implemntation file of this view implementing the IMapView interface.

Then in your PCL project, you get instance of this class by this instruction

IMapView mapView = DependencyService.Get<IMapView>(DependencyFetchTarget.NewInstance);

_mapContainer.Content = mapView as ContentView;

This seems to work in our case.

Eric.

0 Kudos
CharlesMoszkowicz
New Contributor

Hi Eric,

I would also like to use the ESRI Component with a PCL project. Could you explain a little bit more how did you manage to do that ? I've already created a Arcgis Runtime shared project (in the same solution of the PCL). Can you share some code please, specifically the interface in the PCL and the code in the Shared Project.

Thanks

0 Kudos
dotMorten_esri
Esri Notable Contributor

At this point PCL is essentially dead, and getting replaced by .NET Standard.

I think you're better off creating a multi-targeting project instead. That'll set you up great for moving to .NET Standard, while having a single project output you can share.

https://oren.codes/2017/01/04/multi-targeting-the-world-a-single-project-to-rule-them-all/

0 Kudos
dotMorten_esri
Esri Notable Contributor

...I just pushed a sample up on GitHub that demonstrates multi-targeting to help you get started: https://github.com/Esri/arcgis-runtime-demos-dotnet/blob/master/src/MultiTargeting

0 Kudos
EricDUCOS1
New Contributor III

Hi,

There seems to be a problem with my mail box, so the answer did not get into the thread...

I republish my answer below:

-------

Hi Charles,

 

Sorry not to have given answer before…

 

First, I think that Morten given some part of answer just because now when you create a Xamarin Project, PCL project is replaced by .NET Standard project. But I did not test if ArcGIS Runtime SDK .NET is compatible with Standard (I read a thread about that but did not verify…)

 

If you already have a Xamarin with PCL project, you can do something like we have done to arrange the things…

 

In your Shared project you create a Xamarin ContentView with the MapView control. In the code behind, you add an interface like this…

public partial class MapPageView2 : ContentView, IMapView

 

IMapView defines some method that you will use to initialize Map and returning some data from ESRI SDK like layers, or to react to some event like touch .

 

In each specific projet for Android, iOS or Windows, you use DependencyService to register the class defined in the shared project like for example:

DependencyService.Register<IMapView, MapPageView2>();

 

In he PCL project you define a new Xamarin XAml page tha will contains a ContentView control like:

<ContentView x:Name="_mapContainer" Grid.Row="0"/>

(here my control belongs to a grid…)

 

And somewhere in the code behind of this page, you make the binding….I discovered that this code has to be put in different place according to the plateform…

 

For UWP, this is in the constructo:

if (Device.RuntimePlatform == Device.UWP)

            {

                var mapView = DependencyService.Get<IMapView>(DependencyFetchTarget.NewInstance);

                mapView.SetMap(); // This method defined in the interface and implemented in the class in the shared projet use configuration to load a WebMap in the map control

                _mapContainer.Content = mapView as ContentView;

            }

 

For Android, the same code has to be placed in the OnAppearing…

 

This is not really good coding, but it works…I really hope that the new Standard platform used by new Xamarin project will work without shared project for ArcGIS .NET SDK.

 

I hope that my explanations will help you in some way.

 

Eric.

0 Kudos