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

[nativeaot] support for Application subclasses #9716

Merged
merged 16 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions samples/NativeAOT/JavaInteropRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ static void JNI_OnUnload (IntPtr vm, IntPtr reserved)
static void init (IntPtr jnienv, IntPtr klass)
{
try {
var typeManager = new NativeAotTypeManager ();
var options = new JreRuntimeOptions {
EnvironmentPointer = jnienv,
TypeManager = new NativeAotTypeManager (),
ValueManager = new NativeAotValueManager (),
TypeManager = typeManager,
ValueManager = new NativeAotValueManager (typeManager),
UseMarshalMemberBuilder = false,
JniGlobalReferenceLogWriter = new LogcatTextWriter (AndroidLogLevel.Debug, "NativeAot:GREF"),
JniLocalReferenceLogWriter = new LogcatTextWriter (AndroidLogLevel.Debug, "NativeAot:LREF"),
Expand Down
7 changes: 5 additions & 2 deletions samples/NativeAOT/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using Android.Runtime;
using Android.Util;
using System.Reflection;
using System.Runtime.InteropServices;

namespace NativeAOT;

[Register("my/MainActivity")] // Required for typemap in NativeAotTypeManager
[Activity(Label = "@string/app_name", MainLauncher = true)]
// Name required for typemap in NativeAotTypeManager
[Activity (Label = "@string/app_name", MainLauncher = true, Name = "my.MainActivity")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle? savedInstanceState)
{
Log.Debug ("NativeAOT", "MainActivity.OnCreate()");

base.OnCreate(savedInstanceState);

// Set our view from the "main" layout resource
Expand Down
23 changes: 23 additions & 0 deletions samples/NativeAOT/MainApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Android.Runtime;
using Android.Util;

/// <summary>
/// NOTE: This class is not required, but used for testing Android.App.Application subclasses.
/// Name required for typemap in NativeAotTypeManager
/// </summary>
[Application (Name = "my.MainApplication")]
public class MainApplication : Application
{
public MainApplication (IntPtr handle, JniHandleOwnership transfer)
: base (handle, transfer)
{
Log.Debug ("NativeAOT", $"Application..ctor({handle.ToString ("x2")}, {transfer})");
}

public override void OnCreate ()
{
Log.Debug ("NativeAOT", "Application.OnCreate()");

base.OnCreate ();
}
}
2 changes: 2 additions & 0 deletions samples/NativeAOT/NativeAotRuntimeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public boolean onCreate() {
public void attachInfo(android.content.Context context, android.content.pm.ProviderInfo info) {
Log.d(TAG, "NativeAotRuntimeProvider.attachInfo(): calling JavaInteropRuntime.init()…");
JavaInteropRuntime.init();
// NOTE: only required for custom applications
net.dot.android.ApplicationRegistration.registerApplications();
super.attachInfo (context, info);
}

Expand Down
2 changes: 2 additions & 0 deletions samples/NativeAOT/NativeAotTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ partial class NativeAotTypeManager : JniRuntime.JniTypeManager {
// TODO: list of types specific to this application
Dictionary<string, Type> typeMappings = new () {
["android/app/Activity"] = typeof (Android.App.Activity),
["android/app/Application"] = typeof (Android.App.Application),
["android/content/Context"] = typeof (Android.Content.Context),
["android/content/ContextWrapper"] = typeof (Android.Content.ContextWrapper),
["android/os/BaseBundle"] = typeof (Android.OS.BaseBundle),
["android/os/Bundle"] = typeof (Android.OS.Bundle),
["android/view/ContextThemeWrapper"] = typeof (Android.Views.ContextThemeWrapper),
["my/MainActivity"] = typeof (MainActivity),
["my/MainApplication"] = typeof (MainApplication),
};

public NativeAotTypeManager ()
Expand Down
Loading
Loading