Repository navigation
Description
Android framework version
net11.0-android (Preview)
Affected platform version
.NET 11 Preview 7
Description
dotnet/android has long supported forwarding C# custom attributes to Java annotations within generated Java Callable Wrappers. This also worked when targeting (experimental!) Native AOT:
# net 10!
dotnet new android -n android-jsiface
cd android-jsiface
cat <<'EOF' | git apply
diff --git a/MyWebViewHandler.cs b/MyWebViewHandler.cs
new file mode 100644
index 0000000..a3061b9
--- /dev/null
+++ b/MyWebViewHandler.cs
@@ -0,0 +1,10 @@
+using Android.Webkit;
+
+namespace impl;
+
+public class MyWebViewHandler : Example.WebViewHandlerBase {
+ [JavascriptInterface]
+ public override void PostMessage(string? message)
+ {
+ }
+}
diff --git a/WebViewHandlerBase.java b/WebViewHandlerBase.java
new file mode 100644
index 0000000..a249256
--- /dev/null
+++ b/WebViewHandlerBase.java
@@ -0,0 +1,4 @@
+package example;
+public abstract class WebViewHandlerBase {
+ public abstract void postMessage(String message);
+}
EOF
dotnet publish -r android-arm64 -p:PublishAot=trueThe above would produce obj/Release/net10.0-android/android-arm64/android/src/crc64560613145aa5a4d6/MyWebViewHandler.java, which contained:
@android.webkit.JavascriptInterface
public void postMessage (java.lang.String p0)
{
n_postMessage (p0);
}The C# [JavascriptInterface] custom attribute became the Java @JavascriptInterface annotation.
See: android-jsiface.zip
This worked through .NET 11 Preview 6.
Enter .NET 11 Preview 7, which introduces a modified Java Callable Wrapper generator with scrc64… package names for Native AOT; see 3f54298 and others.
.NEt 11 Preview 7 broke Native AOT support out of the box, but we can work around that by using Directory.Build.targets:
cat <<'EOF' | git apply
diff --git a/Directory.Build.targets b/Directory.Build.targets
new file mode 100644
index 0000000..4af58f5
--- /dev/null
+++ b/Directory.Build.targets
@@ -0,0 +1,14 @@
+<Project>
+ <!--
+ Android+NativeAOT fails with .NET 11 Preview 7 with error NU1102:
+ Unable to find package Microsoft.NETCore.App.Runtime.NativeAOT.android-arm64 with version (= 11.0.0-preview.7.26378.119)
+ …because there is no published 11.0.0-preview.7.26378.119 package; it should be 11.0.0-preview.7.26381.103.
+
+ This is the upstream fix: https://github.com/dotnet/android/pull/12356
+
+ For now, Update `$(MicrosoftNETCoreAppRefPackageVersion)` to the correct version so that NuGet versions are correct.
+ -->
+ <PropertyGroup Condition=" '$(BundledNETCoreAppPackageVersion)' == '11.0.0-preview.7.26381.103' ">
+ <MicrosoftNETCoreAppRefPackageVersion>11.0.0-preview.7.26381.103</MicrosoftNETCoreAppRefPackageVersion>
+ </PropertyGroup>
+</Project>
EOFNext, update $(TargetFramework) to target net11.0-android:
cat <<'EOF' | git apply
diff --git a/android-jsiface.csproj b/android-jsiface.csproj
index 974a617..7834ed0 100644
--- a/android-jsiface.csproj
+++ b/android-jsiface.csproj
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFramework>net10.0-android</TargetFramework>
+ <TargetFramework>net11.0-android</TargetFramework>
<SupportedOSPlatformVersion>24</SupportedOSPlatformVersion>
<RootNamespace>android_jsiface</RootNamespace>
<OutputType>Exe</OutputType>
EOFResulting project: android-jsiface+net11.zip
Build for Native AOT using .NET 11 Preview 7:
dotnet publish -r android-arm64 -p:PublishAot=trueNow, investigate the Java Callable Wrapper for MyWebViewHandler, in obj/Release/net11.0-android/android-arm64/typemap/java/scrc64ea0c4e731f7fd0e6/MyWebViewHandler.java (note the /scrc64…, not /crc64…, which contains:
@Override
public void postMessage (java.lang.String p0)
{
n_PostMessage_Ljava_lang_String_ (p0);
}Note that @android.webkit.JavascriptInterface is not present.
Why does this matter? It breaks JavaScript bridging under Native AOT, which in turn means Uno unit tests fail, e.g. When_WebMessageReceived() (which is a timeout, and not really meaningful to anyone), but the cause is the missing @JavascriptInterface annotation within the Java Callable Wrapper.
Steps to Reproduce
Did you find any workaround?
No.
Activity
jonpryor commentedon Aug 27, 2026
On Discord, @jonathanpeppers mentioned a possible workaround: set
$(_AndroidTypeMapImplementation)=llvm-ir. This will apparently become the$(AndroidTypeMapImplementation)MSBuild property in .NET 11 RC1.test: ignore failing tests Android+NativeAOT tests.
test: ignore failing tests Android+NativeAOT tests.
test: ignore failing tests Android+NativeAOT tests.
[NativeAOT] Forward JCW Java annotations (dotnet#12549)
test: ignore failing tests Android+NativeAOT tests.
test: ignore failing tests Android+NativeAOT tests.
[tests] Cover WebView JavaScript annotations (#12608)