Commit 21975794 added samples/Hello-NativeAOTFromJNI, which
demonstrated the use of NativeAOT to create a native library which
could be loaded and used by a Java application.
What else supports loading native libraries for use by a "Java"
environment? Android!
Take the core infrastructure from Hello-NativeAOTFromJNI, have
the binary output target linux-bionic-arm64 --
the $(RuntimeIdentifier) for .NET using Android's "bionic" libc
while not using .NET for Android -- and then use gradlew to
package that native library into an Android application.
Add "degrees" of Android and Gradle Integration:
samples/Hello-NativeAOTFromAndroid/app is an Android project
with Gradle build scripts.
gradlew :app:processReleaseResources is executed as a pre-build
step to get an R.txt describing all the Android Resources
contained within the Android project. The new
<ParseAndroidResources/> task parses R.txt and generates an
R.g.cs, allowing C# code to reference some Android resources,
such as the Android layout to display.
android.xml contains a (very!) minimal API description of
android.jar. It is used in a pre-build step to produce bindings
of android.app.Activity and android.os.Bundle (among others),
allowing us to write a C# subclass of Activity and show
something on-screen.
After the C# build, we:
use jcw-gen to generate Java Callable Wrappers (JCW) of
Java.Lang.Object subclasses,
use jnimarshalmethod-gen to generate JNI marshal methods
for methods such as MainActivity.OnCreate(), so that
C# code can override Java methods.
As a post-Publish step, we copy various artifacts into the
Android project structure so that they can be packaged into the
Android app-release.apk, then invoke gradlew assembleRelease
to generate app-release.apk.
Update generator to support using Java.Base.dll as a referenced
assembly for binding purposes, in particular by supporting the use
of [JniTypeSignatureAttribute] on already bound types. No usable
bindings of types in android.xml could be generated without this.
Update jcw-gen to appropriately support
[JniTypeSignature(GenerateJavaPeer=false)] when determining the
constructors that a Java Callable Wrapper should contain. Failure to
do so meant that the JCW for MainActivity contained constructors
that shouldn't be there, resulting in javac errors.
Update jcw-gen to and support JavaInterop1-style method overrides.
Failure to do so meant that the JCW for MainActivitydidn't
declare an onCreate() method.
Context: 2197579478152fbc815eb15195977f808cd6bde4
Commit 21975794 added
samples/Hello-NativeAOTFromJNI
, which demonstrated the use of NativeAOT to create a native library which could be loaded and used by a Java application.What else supports loading native libraries for use by a "Java" environment? Android!
Take the core infrastructure from
Hello-NativeAOTFromJNI
, have the binary output targetlinux-bionic-arm64
-- the$(RuntimeIdentifier)
for .NET using Android's "bionic" libc while not using .NET for Android -- and then usegradlew
to package that native library into an Android application.Add "degrees" of Android and Gradle Integration:
samples/Hello-NativeAOTFromAndroid/app
is an Android project with Gradle build scripts.gradlew :app:processReleaseResources
is executed as a pre-build step to get anR.txt
describing all the Android Resources contained within the Android project. The new<ParseAndroidResources/>
task parsesR.txt
and generates anR.g.cs
, allowing C# code to reference some Android resources, such as the Android layout to display.android.xml
contains a (very!) minimal API description ofandroid.jar
. It is used in a pre-build step to produce bindings ofandroid.app.Activity
andandroid.os.Bundle
(among others), allowing us to write a C# subclass ofActivity
and show something on-screen.After the C# build, we:
jcw-gen
to generate Java Callable Wrappers (JCW) ofJava.Lang.Object
subclasses,jnimarshalmethod-gen
to generate JNI marshal methods for methods such asMainActivity.OnCreate()
, so that C# code can override Java methods.As a post-
Publish
step, we copy various artifacts into the Android project structure so that they can be packaged into the Androidapp-release.apk
, then invokegradlew assembleRelease
to generateapp-release.apk
.Update
generator
to support usingJava.Base.dll
as a referenced assembly for binding purposes, in particular by supporting the use of[JniTypeSignatureAttribute]
on already bound types. No usable bindings of types inandroid.xml
could be generated without this.Update
jcw-gen
to appropriately support[JniTypeSignature(GenerateJavaPeer=false)]
when determining the constructors that a Java Callable Wrapper should contain. Failure to do so meant that the JCW forMainActivity
contained constructors that shouldn't be there, resulting injavac
errors.Update
jcw-gen
to and supportJavaInterop1
-style method overrides. Failure to do so meant that the JCW forMainActivity
didn't declare anonCreate()
method.