Skip to content
Draft
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ static int JNI_OnLoad (IntPtr vm, IntPtr reserved)
try {
AndroidLog.Print (AndroidLogLevel.Info, "JavaInteropRuntime", "JNI_OnLoad()");
XA_Host_NativeAOT_JNI_OnLoad (vm, reserved);
LogcatTextWriter.Init ();
return (int) JniVersion.v1_6;
return (int)JniVersion.v1_6;
}
catch (Exception e) {
AndroidLog.Print (AndroidLogLevel.Error, "JavaInteropRuntime", $"JNI_OnLoad() failed: {e}");
return 0;
}
}

[UnmanagedCallersOnly (EntryPoint="JNI_OnUnload")]
[UnmanagedCallersOnly(EntryPoint = "JNI_OnUnload")]
static void JNI_OnUnload (IntPtr vm, IntPtr reserved)
{
AndroidLog.Print(AndroidLogLevel.Info, "JavaInteropRuntime", "JNI_OnUnload");
Expand All @@ -42,17 +41,12 @@ static void init (IntPtr jnienv, IntPtr klass, IntPtr classLoader)
{
JniTransition transition = default;
try {
var settings = new DiagnosticSettings ();
settings.AddDebugDotnetLog ();

var options = new NativeAotRuntimeOptions {
EnvironmentPointer = jnienv,
ClassLoader = new JniObjectReference (classLoader, JniObjectReferenceType.Global),
TypeManager = new ManagedTypeManager (),
ValueManager = ManagedValueManager.GetOrCreateInstance (),
UseMarshalMemberBuilder = false,
JniGlobalReferenceLogWriter = settings.GrefLog,
JniLocalReferenceLogWriter = settings.LrefLog,
};
runtime = options.CreateJreVM ();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,58 +1,12 @@
// NOTE: logging methods below are need temporarily due to:
// 1) linux-bionic BCL doesn't redirect stdout/stderr to logcat
// 2) Android.Util.Log won't work until we initialize the Java.Interop.JreRuntime
// NOTE: logging methods below are need temporarily because
// Android.Util.Log won't work until we initialize the Java.Interop.JreRuntime

using System.IO;
using System.Runtime.InteropServices;
using System.Text;

namespace Microsoft.Android.Runtime;

internal sealed class LogcatTextWriter : TextWriter {

public static void Init ()
{
// This method is a no-op, but it's necessary to ensure the static
// constructor is executed.
}

static LogcatTextWriter ()
{
Console.SetOut (new LogcatTextWriter (AndroidLogLevel.Info));
Console.SetError (new LogcatTextWriter (AndroidLogLevel.Error));
}

AndroidLogLevel Level;
string Tag;

internal LogcatTextWriter (AndroidLogLevel level, string tag = "NativeAotFromAndroid")
{
Level = level;
Tag = tag;
}

public override Encoding Encoding => Encoding.UTF8;
public override string NewLine => "\n";

public override void WriteLine (string? value)
{
if (value == null) {
AndroidLog.Print (Level, Tag, "");
return;
}
ReadOnlySpan<char> span = value;
while (!span.IsEmpty) {
if (span.IndexOf ('\n') is int n && n < 0) {
break;
}
var line = span.Slice (0, n);
AndroidLog.Print (Level, Tag, line.ToString ());
span = span.Slice (n + 1);
}
AndroidLog.Print (Level, Tag, span.ToString ());
}
}

static class AndroidLog {

[DllImport ("log", EntryPoint = "__android_log_print", CallingConvention = CallingConvention.Cdecl)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class NativeAotRuntimeOptions : JniRuntime.CreationOptions {

public bool IgnoreUnrecognizedOptions {get; set;}

public TextWriter? JniGlobalReferenceLogWriter {get; set;}
public TextWriter? JniLocalReferenceLogWriter {get; set;}

public NativeAotRuntimeOptions ()
{
JniVersion = JniVersion.v1_2;
Expand Down
Loading