Skip to content
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: 5 additions & 0 deletions samples/NativeAOT/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Android.Content.Res;
using Android.Runtime;
using Android.Util;
using System.Reflection;
Expand All @@ -17,5 +18,9 @@ protected override void OnCreate(Bundle? savedInstanceState)

// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);

// An example of an Android API that uses a Java array
var list = new ColorStateList (new int[][] { [ 0, 1 ]}, [0, 1]);
Log.Debug ("NativeAOT", "MainActivity.OnCreate() ColorStateList: " + list);
}
}
11 changes: 10 additions & 1 deletion src/Mono.Android/Android.Runtime/JNIEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,16 @@ public static IntPtr FindClass (System.Type type)
{
int rank = JavaNativeTypeManager.GetArrayInfo (type, out type);
try {
return FindClass (JavaNativeTypeManager.ToJniName (GetJniName (type), rank));
var sig = JNIEnvInit.androidRuntime?.TypeManager.GetTypeSignature (type) ?? default;
if (!sig.IsValid || sig.SimpleReference == null) {
sig = new JniTypeSignature ("java/lang/Object");
}
sig = sig.AddArrayRank (rank);

JniObjectReference local_ref = JniEnvironment.Types.FindClass (sig.Name);
IntPtr global_ref = local_ref.NewGlobalRef ().Handle;
JniObjectReference.Dispose (ref local_ref);
return global_ref;
} catch (Java.Lang.Throwable e) {
if (!((e is Java.Lang.NoClassDefFoundError) || (e is Java.Lang.ClassNotFoundException)))
throw;
Expand Down
Loading