Mono for Android Project does not work with libraries oriented to .NET framework 4

I use Mono for Android to create an Android application that uses a large number of class libraries already developed. When I add a project as a link to an Android app, I get a warning with a message

Warning 1 You cannot reference the project "Project Name". A linked project targets another family of frames (.NETFramework)

My project targets the .NET Framework 4. My Android application says "Minimum Android for target = Android 4.0."

This is a warning, but when I add a using statement to the Activity.cs class in an Android application, I get a few errors that appear in the specified library. Then, if I delete the using statement and rebuild, the errors go away.

Do I need to change some settings in a Mono project for Android in order to be able to reference libraries designed for the .NET framework 4.0?

+6
source share
1 answer

You cannot reference libraries targeting the .Net infrastructure.

What you need to do if you want to reuse this code is to create a new Android class library project and add files from your existing .Net library as โ€œlinkedโ€ files. This is a way to get code reuse within frameworks.

As an example, consider the RestSharp project on GitHub. You can see projects for MonoDroid, MonoTouch, etc. They do not have files, but links to a common source.

I hope in your case all the code in your existing libraries is compatible with the MonoDroid environment profile. Otherwise, you will need to include preprocessor directives - this can also be seen in RestSharp.

+5
source

Source: https://habr.com/ru/post/925332/


All Articles