Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoreCLR, CoreRT and Android #63384

Closed
simplejackcoder opened this issue Jan 5, 2022 · 19 comments
Closed

CoreCLR, CoreRT and Android #63384

simplejackcoder opened this issue Jan 5, 2022 · 19 comments

Comments

@simplejackcoder
Copy link
Contributor

I want to write parts of my Android application in C#. I don't care about a good developer experience or a supported path necessarily but want to know if CoreCLR (the full runtime) or CoreRT can be compiled against Android NDK platform headers and the basic runtime facilities like GC, exception handling, Null reference handling work. In addition, networking & dns resolution working would be a plus.

I know ARM64 support has come a long way, but I wonder if Android platform support issues are still lurking and how many (if any) issues have been diagnosed.

I'm also interested in CoreRT, because although my application is written in C# it uses very little of the .net libraries, but does rely on GC, exception handling.

I'm not interested in Mono or Xamarin.

@dotnet-issue-labeler dotnet-issue-labeler bot added area-Meta untriaged New issue has not been triaged by the area owner labels Jan 5, 2022
@ghost
Copy link

ghost commented Jan 5, 2022

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Issue Details

I want to write parts of my Android application in C#. I don't care about a good developer experience or a supported path necessarily but want to know if CoreCLR (the full runtime) or CoreRT can be compiled against Android NDK platform headers and the basic runtime facilities like GC, exception handling, Null reference handling work. In addition, networking & dns resolution working would be a plus.

I know ARM64 support has come a long way, but I wonder if Android platform support issues are still lurking and how many (if any) issues have been diagnosed.

I'm also interested in CoreRT, because although my application is written in C# it uses very little of the .net libraries, but does rely on GC, exception handling.

I'm not interested in Mono or Xamarin.

Author: simplejackcoder
Assignees: -
Labels:

area-Meta, untriaged

Milestone: -

@simplejackcoder
Copy link
Contributor Author

dotnet/corert#8316 @RalfKornmannEnvision @jkotas seem to be working on this. Any update? Is CoreRT with no real .net libraries but only exception handling and GC and null ref working?

ClangSharp by @tannergooding could then be used to generate Android NDK headers C# equivalent and at least developers can write C# for their Android applications without using Mono.

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Jan 5, 2022

I looked into this in the context of NativeAOT (previously named CoreRT) briefly two weeks ago. I have a patch here that gets a build out, but the developer experience around it is not pretty. I haven't actually gotten to testing it too much because I ran out of time I allocated for it and I don't have a pressing need for this right now:

MichalStrehovsky@0e17083

The commit has high level description of what to do with it once you get the libraries built.

Cc @kant2002 who was also interested in this in the past.

@jkotas jkotas added this to the Future milestone Jan 5, 2022
@simplejackcoder
Copy link
Contributor Author

@MichalStrehovsky the developer experience doesn't need to be pretty, I've seen your work and at least you document the experience even if the steps are onerous. The basic point is that there is a large portion of code, whether ML models, or other on-device logic that a variety of developers have written in C# that could be activated for the developer who is experienced or willing to put in the work.

But not all developers are familiar with getting exception handling, other low level quirks needed for a building NativeAOT without your and others expertise.

Thank you I will look into this commit.

@jeffschwMSFT jeffschwMSFT removed the untriaged New issue has not been triaged by the area owner label Jan 11, 2022
@josephmoresena
Copy link
Contributor

I am working on a small project to port JNI to .Net to be usable with NativeAOT.
I haven't made much progress as it is a hobby project however at least on x64 platforms JNI is perfectly functional with NativeAOT. I have tried to compile the library using the NDK but there are problems many problems with linker.

@MichalStrehovsky
Copy link
Member

Nice! What are the linker problems you're seeing? Did you build for ARM64 Android using the above commit?

@ghost
Copy link

ghost commented Feb 7, 2022

Tagging subscribers to 'arch-android': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

I want to write parts of my Android application in C#. I don't care about a good developer experience or a supported path necessarily but want to know if CoreCLR (the full runtime) or CoreRT can be compiled against Android NDK platform headers and the basic runtime facilities like GC, exception handling, Null reference handling work. In addition, networking & dns resolution working would be a plus.

I know ARM64 support has come a long way, but I wonder if Android platform support issues are still lurking and how many (if any) issues have been diagnosed.

I'm also interested in CoreRT, because although my application is written in C# it uses very little of the .net libraries, but does rely on GC, exception handling.

I'm not interested in Mono or Xamarin.

Author: simplejackcoder
Assignees: -
Labels:

os-android, area-NativeAOT-coreclr

Milestone: Future

@josephmoresena
Copy link
Contributor

Nice! What are the linker problems you're seeing? Did you build for ARM64 Android using the above commit?

Not with that commit yet, I promise to do it in the medium term!
I tried to do it with cross-architecture compilation but with android-arm64 RID.
The problems I ran into were that the NDK clang version of the has problems with the following statements:
-lgssapi_krb5 -lrt
--require-defined,CoreRT_StaticInitialization -Wl,

Removing them I was able to create a .so with libc++_shared.so dependency but when the Android App tried to load it a missing symbol error was ocurred.

@josephmoresena
Copy link
Contributor

Nice! What are the linker problems you're seeing? Did you build for ARM64 Android using the above commit?

It took me too long to get it but I finally get to successfully compile a JNI library and use it from an Android Application. NativeAOT is GREAT!!!!

@kant2002
Copy link
Contributor

@josephmoresena would be great if you share small sample, so everybody could follow your lead!

@josephmoresena
Copy link
Contributor

josephmoresena commented Feb 12, 2022

@josephmoresena would be great if you share small sample, so everybody could follow your lead!

Of course, I still don't know all this about Android very well (I had not used Android Studio for many years) but the idea is to do something like this:
https://github.com/android/ndk-samples/tree/android-mk/hello-jni

It makes me really very happy because it motivates me even more to continue with the project that I mentioned above.

@josephmoresena
Copy link
Contributor

@josephmoresena would be great if you share small sample, so everybody could follow your lead!

The sample is now in this repo. I decided to no include the Android code.
https://github.com/josephmoresena/NativeAOT-AndroidHelloJniLib

@MichalStrehovsky
Copy link
Member

Support for Bionic builds with the Mono runtime was merged in #66147. The maximum I can see in terms of Android support with NativeAOT is that - Bionic is Android, but without the Java interop part (we don't have plans for Java interop outside Mono).

The Bionic configuration could be useful for people who want to build a shared library they can call into like the example from Joseph above, but wouldn't be enough to build entire MAUI apps. There's Mono for that.

@squidink7
Copy link

Now that iOS support in NativeAOT is being discussed (#80905), is there a possibility of Android support being extended to include some basic Java Interop? While porting MAUI is understandably a non-starter (at least for now), having enough to run something like Avalonia which renders its own controls might be a bit easier. It would be really nice to have particularly the startup and size benefits of NativeAOT (which have been the largest pain points for me) in .NET android apps.

@steveisok
Copy link
Member

@squidink7 nothing is being planned for Android at this time. iOS support has a fair amount of work and so our focus is there.

@josephmoresena
Copy link
Contributor

Now that iOS support in NativeAOT is being discussed (#80905), is there a possibility of Android support being extended to include some basic Java Interop? While porting MAUI is understandably a non-starter (at least for now), having enough to run something like Avalonia which renders its own controls might be a bit easier. It would be really nice to have particularly the startup and size benefits of NativeAOT (which have been the largest pain points for me) in .NET android apps.

I'm working on a C# implementation of JNI for use with NativeAOT. Actually this would go much further than Android (even if my real goal is Android), however, with Android there would be many more problems, we may need to do many things with Android's native libraries (Implementing headers in .NET using PInvoke) or with Java directly (using JNI ). A lot of .NET stuff just doesn't work on Bionic + NativeAOT (Globalization and Networking).

@marek-safar
Copy link
Contributor

@lambdageek

@MichalStrehovsky
Copy link
Member

We now have builds for Bionic (#86781) but there's some MSBuild targets work left. That one is tracked in #87340 and should be on track for .NET 8.0.

@MineCake147E
Copy link
Contributor

MineCake147E commented Jun 13, 2023

Is there any chance to see RyuJIT running on Android?
I think JIT is the key to taking full advantage of all the features of the C#.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants