Prism: I create a Xamarin.Forms solution but Xamarin.Android cannot build

Created on 18 May 2018  路  10Comments  路  Source: PrismLibrary/Prism

My environment as following
Windows 10 : 1709
Visual Studio 2017 : 15.7.1
Prism Template Pack : 2.0.9

My problem is :

  1. I create a Xamarin.Forms solution by Prism Template Pack

  2. build the Xamarin.Android project, then I got following error message:

Error       Your project is not referencing the "MonoAndroid,Version=v8.1" framework. Add a reference to "MonoAndroid,Version=v8.1" in the "frameworks" section of your project.json, and then re-run NuGet restore.    BlankApp1.Android

But when I have changed the target Android version of Application of Xamarin.Android property to Android 7.1

And I can build this Xamarin.Adnroid project without any error and can run on emulator.

You can reference the test Visual Studio Project : https://github.com/vulcanlee/CannotBuildAndroid

Most helpful comment

I have the same problem.
Reason: file obj/project.assets.json target "MonoAndroid,Version=v7.1" when my project target android version 8.1
I resolved it by:

  1. Right click Android project => Properties => Application => Compile
    using Android version => Android 7.1
  2. Clean and Build project => build success, and restart IDE.
  3. Right click Android project => Properties => Application => Compile
    using Android version => Android 8.1
  4. Clean and Build project => build success

File obj/project.assets.json updated to "MonoAndroid,Version=v8.1"

All 10 comments

Following is the .csproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{BE0624F1-7930-439B-A633-DE63C4A4FC8B}</ProjectGuid>
    <ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>BlankApp1.Droid</RootNamespace>
    <AssemblyName>BlankApp1.Android</AssemblyName>
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkVersion>v7.1</TargetFrameworkVersion>
    <AndroidApplication>True</AndroidApplication>
    <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
    <AndroidResgenClass>Resource</AndroidResgenClass>
    <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
    <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
    <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
    <AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
    <AndroidStoreUncompressedFileExtensions />
    <MandroidI18n />
    <JavaMaximumHeapSize />
    <JavaOptions />
    <NuGetPackageImportStamp></NuGetPackageImportStamp>
  </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>
    <AndroidLinkMode>None</AndroidLinkMode>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <AndroidManagedSymbols>true</AndroidManagedSymbols>
    <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Mono.Android" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="2.5.0.122203" />
    <PackageReference Include="Xamarin.Android.Support.Design" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v4" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="25.4.0.2" />
    <PackageReference Include="Prism.Unity.Forms" Version="7.0.0.396" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="MainActivity.cs" />
    <Compile Include="Resources\Resource.Designer.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Resources\AboutResources.txt" />
    <None Include="Assets\AboutAssets.txt" />
  </ItemGroup>
  <ItemGroup>
    <AndroidResource Include="Resources\mipmap-hdpi\ic_launcher.png" />
    <AndroidResource Include="Resources\mipmap-mdpi\ic_launcher.png" />
    <AndroidResource Include="Resources\mipmap-xhdpi\ic_launcher.png" />
    <AndroidResource Include="Resources\mipmap-xxhdpi\ic_launcher.png" />
    <AndroidResource Include="Resources\mipmap-xxxhdpi\ic_launcher.png" />
  </ItemGroup>
  <ItemGroup>
    <None Include="Properties\AndroidManifest.xml" />
  </ItemGroup>
  <ItemGroup>
    <AndroidResource Include="Resources\layout\Tabbar.axml" />
    <AndroidResource Include="Resources\layout\Toolbar.axml" />
    <AndroidResource Include="Resources\values\styles.xml">
      <SubType>Designer</SubType>
    </AndroidResource>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\BlankApp1\BlankApp1.csproj">
      <Project>{A682884C-CB44-4A89-B752-27BB634E0ABE}</Project>
      <Name>BlankApp1</Name>
    </ProjectReference>
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>

I've seen this error numerous times on different solutions and different machines, both mac and pc. I've been most successful getting around this error by checking the Android sdk manager. I cannot explain why, but things seem to start working only when I've got Android 7.1, 8.0, and 8.1 all installed.

If it still won't compile after that, I recommend deleting all bin & obj directories in your solution's projects. Then restore nuget packages and try to build one more time.

I know this is not a satisfying answer, but at least it might help get you going. Perhaps someone else will be able to shed a bit more insight onto what's going on.

@vulcanlee the error would seem to be related to the issue that @jbachelor mentioned. Make sure that you have Android 8.1 SDK installed.

@dansiegel

Yes, I have Android 8.1 SDK installed

I have removed Android 8.1 SDK and the problem is disappeared.

Thanks for your help.

I have the same problem.
Reason: file obj/project.assets.json target "MonoAndroid,Version=v7.1" when my project target android version 8.1
I resolved it by:

  1. Right click Android project => Properties => Application => Compile
    using Android version => Android 7.1
  2. Clean and Build project => build success, and restart IDE.
  3. Right click Android project => Properties => Application => Compile
    using Android version => Android 8.1
  4. Clean and Build project => build success

File obj/project.assets.json updated to "MonoAndroid,Version=v8.1"

@nqbjnh Thank you!!!

@nqbjnh Could you explain me how to fix in Visual Studio for Mac?

@nqbjnh Could you explain me how to fix in Visual Studio for Mac?
I don't use VS for Mac. I am not sure the same VS for Windows. You can check MonoAndroid version in project.assets.json file and project

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings