Xamarin Forms PCL项目能否集成Esri GIS SDK?新手技术咨询
Hey there! Let me walk you through this since I’ve worked with Xamarin Forms and Esri’s GIS SDKs before:
Can I use the Esri GIS SDK in my PCL project?
Yes you can! Esri’s ArcGIS Runtime SDK for .NET provides a .NET Standard library that works seamlessly with Xamarin Forms PCL projects—as long as your PCL targets .NET Standard 2.0 or higher. Most modern Xamarin Forms PCLs are set up for this by default, but double-check your project’s target framework to be sure.
Do I have to switch to a Shared Project?
Nope, switching to a Shared Project isn’t required. The .NET Standard-based Esri SDK is designed to work with PCLs (or .NET Standard libraries) so you can keep your shared code in the PCL and only handle platform-specific setup in your iOS/Android projects. Shared Projects are an alternative approach, but they’re not a hard requirement here.
Are there separate Xamarin Esri SDKs for iOS and Android?
Absolutely! Esri provides platform-specific packages for both Xamarin.iOS and Xamarin.Android alongside the .NET Standard library. These platform packages handle native initialization, permissions, and any device-specific functionality that the shared .NET Standard library can’t cover on its own.
Step-by-Step Solution to Set This Up
Here’s how to get everything working smoothly:
Verify your PCL’s target framework
- Right-click your PCL project → Properties → Application
- Make sure the target framework is set to .NET Standard 2.0 or higher (if it’s an older PCL Profile, you’ll want to upgrade it to .NET Standard—Esri no longer supports legacy PCL Profiles).
Install the shared Esri package in your PCL
- Use NuGet Package Manager to install
Esri.ArcGISRuntime.Xamarin.Formsin your PCL project. This pulls in the .NET Standard library you’ll use for shared map logic.
- Use NuGet Package Manager to install
Set up the iOS project
- Install
Esri.ArcGISRuntime.Xamarin.iOSvia NuGet in your iOS project. - In
AppDelegate.cs, add this line to theFinishedLaunchingmethod to initialize the SDK:Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.Initialize(); - Don’t forget to add required permissions to
Info.plist(e.g., location access for maps: addNSLocationWhenInUseUsageDescriptionwith a description of why you need location access).
- Install
Set up the Android project
- Install
Esri.ArcGISRuntime.Xamarin.Androidvia NuGet in your Android project. - In
MainActivity.cs, add this line to theOnCreatemethod to initialize the SDK:Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.Initialize(); - Add necessary permissions to
AndroidManifest.xml, like:<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- Install
Use Esri controls in your PCL Xamarin.Forms code
- Here’s a quick example of adding a map to your main page:
using Esri.ArcGISRuntime.Mapping; using Esri.ArcGISRuntime.Xamarin.Forms; namespace YourAppNamespace { public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); // Create a map view and a base map var mapView = new MapView(); var baseMap = new Map(BasemapStyle.ArcGISStreets); mapView.Map = baseMap; // Add the map view to your page Content = mapView; } } }
- Here’s a quick example of adding a map to your main page:
Quick Note
Make sure your Xamarin.Forms version is compatible with the Esri SDK version you install—stick to the latest stable releases of both to avoid compatibility issues.
内容的提问来源于stack exchange,提问作者PritiPriri

