Deploying to Android is using the wrong dll

Kevin Delval 186 Reputation points
2021-09-29T17:57:02.42+00:00

I have recently started creating a multi-platform PCL with all manner of views, effects and other Xamarin utilities for use in any number of projects. Because some of these have platform-specific code and I do not want to include Android dependencies on iOS, for example, I decided to make this target different frameworks.

136360-image.png

136290-image.png

When I build this library, it correctly creates two output folders where the dll in the monoandroid folder contains the implementations specific to Android, and the netstandard2.1 folder does not.

However, after adding a project reference to this PCL for my Sample project (which I keep in the same solution), it seems to always pick up the netstandard2.1 dll, instead of the Android one.

136270-image.png

136391-sigmaxf-microsoft-visual-studio.jpg

After using dotPeek to look into the dll placed in the bin folder of my Sample.Android project, I've confirmed that it's the one built for the netstandard TargetFramework.

What could be causing the Android project to pick up the wrong .dll? I have a suspicion is might be a limitation with Project References and that I might need to reference a NuGet package instead. That would be rather annoying for testing though...

Any help would be welcome.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,293 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,234 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,936 Reputation points
    2021-09-30T05:26:39.31+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    TargetFramework is not supported to set as MonoAndroid, you could right click the shared project -> Properties, to check the value list of this option.

    Because some of these have platform-specific code and I do not want to include Android dependencies on iOS

    The default value of Condition will apply the configuration according to the running platform. It'wll not include a native dependencies to another platform.

       <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">  
         <DebugType>portable</DebugType>  
         <DebugSymbols>true</DebugSymbols>  
       </PropertyGroup>  
    

    You could check the reference of the platform project. For example, Android project does not reference the iOS project.

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful