Search code examples
visual-studioxamarin.androidmononugetnuget-package

Xamarin.Android: Package XX is not compatible with monoandroid81 (MonoAndroid,Version=v8.1)


I encounter a stranger behavior with a Xamarin.Android project in Visual Studio on Windows.

I've created a new Android blank project, and I try ton install the NuGet package "AForge" (a mathematics library), but I get the following error message:

Package AForge 2.2.5 is not compatible with monoandroid81 (MonoAndroid,Version=v8.1).

I've already tried to re create several projects, after having relaunched Visual Studio and the computer, but the problem is still the same.

However, if I do the same thing on Mac, through Visual Studio for Mac, I don't encounter the same problem: the package is well installed.

In add, I can see in the package.config file, that the package il well related to monodroid81:

<?xml version="1.0" encoding="utf-8"?>
<packages>
    <package id="AForge" version="2.2.5" targetFramework="monoandroid81" />
</packages>

Would you have any explanation about this issue?

Update: new issue

Hi @Leo Liu-MSFT, I come back to you as I encounter an new issue. The dll copy works fine locally, but I get an error on AppCenter:

CoreCompile:
/Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/4.5/csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE;XAMARIN_ANDROID_v1_0;MOBILE;ANDROID;ANDROID_1;ANDROID_2;ANDROID_3;ANDROID_4;ANDROID_5;ANDROID_6;ANDROID_7;ANDROID_8;ANDROID_9;ANDROID_10;ANDROID_11;ANDROID_12;ANDROID_13;ANDROID_14;ANDROID_15;ANDROID_16;ANDROID_17;ANDROID_18;ANDROID_19;ANDROID_20;ANDROID_21;ANDROID_22;ANDROID_23;ANDROID_24;ANDROID_25;ANDROID_26;ANDROID_27 /reference:/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Java.Interop.dll /reference:/Users/vsts/.nuget/packages/microsoft.appcenter.analytics/1.7.0/lib/MonoAndroid403/Microsoft.AppCenter.Analytics.Android.Bindings.dll /reference:/Users/vsts/.nuget/packages/microsoft.appcenter.analytics/1.7.0/lib/MonoAndroid403/Microsoft.AppCenter.Analytics.dll /reference:/Users/vsts/.nuget/packages/... Services/AudioService.cs(8,7): error CS0246: The type or namespace name 'AForge' could not be found (are you missing a using directive or an assembly reference?) [/Users/vsts/agent/2.136.1/work/1/s/XxxApp/XxxApp.csproj] Done Building Project "/Users/vsts/agent/2.136.1/work/1/s/XxxApp/XxxApp.csproj" (PackageForAndroid target(s)) -- FAILED.

So I tried your suggestion, but I get an error when I try to save the package:

a local file header is corrupted'

Would you have another suggestion?


Solution

  • Would you have any explanation about this issue?

    You can get the official document here:

    Description: With PackageReference, assemblies present at the root of lib folder without a target framework specific sub-folder are ignored. NuGet looks for a sub-folder matching the target framework moniker (TFM) corresponding to the project’s target framework and installs the matching assemblies into the project.

    In this case, NuGet will consider installing this package to the .NET Framework, which is not compatible with monoandroid81. Then you will that error "Package AForge 2.2.5 is not compatible with monoandroid81".

    To resolve this issue, the best way is contact the author of the AForge NuGet package to update this package, or you can also add reference dll file directly to your project.

    Besides, if you still want to use nuget to manager this package, I would like provide you a workaround to resolve this issue:

    1. Download this nuget package from nuget.org.

    2. Copy the download package, rename it with .zip, like aforge.2.2.5 - Copy.nupkg.zip, then unzip it.

    3. Open the package aforge.2.2.5.nupkg with NuGet Package Explorer(Get it from Microsoft store), add a new folder MonoAndroid81 under the lib node, add exists file AForge.dll and AForge.xml from the copy folder aforge.2.2.5 - Copy.nupkg.zip, save this nuget package.

    4. Add this new create nuget package to the nuget local feed, then add this nuget package to the project. Do not forget delete the nuget package cache in the C:\Users\<UserName>\.nuget\packages\aforge before you add the package.

    Hope this helps.