我想知道如何创建一个针对Android Kitkat最低版本(API 19)的Xamarin.Forms项目,而不使用共享项目选项。
自the minimum supported Android version is Nougat以来,.Net标准库不是一个选项。我的目标用户中有很大一部分(超过40%)仍然使用Android版本低于Nougat的手机。
在Visual Studio 15.5.1或更高版本中,在使用跨平台应用程序模板创建新的Xamarin.Forms项目时,代码共享策略部分下未提供PCL选项。
有人指出,PCL现在已经在Xamarin's Forum和Visual Studio Developer Community上弃用了
关键支持问题:
compileSdkVersion
)与“最低Android版本”(targetSdkVersion
)的“目标框架”(minSdkVersion
)感到困惑。
你的Xamarin.Form
项目必须使用Nougat / 7.0(MonoAndroid7.0
)或更高版本的目标框架,但可以达到最低4.0.3 / IceCreamSandwich版本。
注意:最新版本的Forms需要8.0的目标框架
Xamarin有一个很棒的指南,解释了Android与Xamarin.Android
之间的关系
Understanding Android API Levels.csproj
(参见基本的.csproj
)。.csproj
:<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C38DBA87-39CB-4FD5-B409-6D19E6ED54C8}</ProjectGuid>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<UseMSBuildEngine>true</UseMSBuildEngine>
<OutputType>Library</OutputType>
<RootNamespace>PCLTemplate</RootNamespace>
<AssemblyName>PCLTemplate</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="MyClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
</Project>