Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert .NET Standard class library to native aar/jar

Currently, we are developing a .NET Standard class library that will be used by different Xamarin.* platforms.

I was wondering if there is a way to use the shared code in a native Android project (maybe produce an AAR/JAR file).

The reason I need this functionality is because our company provides an AAR to one of our customers (that is used by a native Android project), and we would like to keep a single source base instead of two.

Thanks in advance!

like image 342
Tomer Domshlak Avatar asked Jan 29 '23 11:01

Tomer Domshlak


1 Answers

Update:

The name changed to ".NET Embedding" and it is at v0.4 at the time of this update.

  • https://developer.xamarin.com/releases/dotnetembedding/dotnetembedding_0/dotnetembedding_0.4/

New instructions:

  • Installing .NET Embedding

Original post:

You can use Mono's Embeddinator-4000

It supports various language consumers, so it surfaces .NET code as idiomatic code in the target language. This is the list of supported languages at present:

  • Objective-C: mapping .NET to idiomatic Objective-C APIs.
  • Java: mapping .NET to idiomatic Java APIs.
  • C: mapping .NET to an object-oriented like C APIs.

Embeddinator-4000 is a tool that allows your existing .NET Code (C#, F# and others) to be consumed from other programming languages and in various different environments.

Java is currently in a preview state for macOS, Windows, and Android.

The platform is selected by passing the --platform= command-line argument to the embeddinator. Currently macOS, Windows, and Android are supported.

re: https://mono.github.io/Embeddinator-4000/

As a part of the requires For Android you will need Xamarin.Android 7.4.99+ and Android Studio 3+ (Java 1.8) but if you are building Android apps with Xamarin and Java you would have those already.

Note: This tool is in Preview, so review the open issues and post new if needed.

re: https://github.com/mono/Embeddinator-4000/issues

Note: This is not trans-compiling, but embedding Mono's runtime in a native package that allow CIL code, AOT'd (i.e. iOS) or not to run within a different language/runtime.

like image 158
SushiHangover Avatar answered Feb 11 '23 06:02

SushiHangover