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
2 changes: 2 additions & 0 deletions Documentation/docs-mobile/TOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@
href: messages/xa4237.md
- name: XA4239
href: messages/xa4239.md
- name: XA4240
href: messages/xa4240.md
- name: XA4241
href: messages/xa4241.md
- name: XA4242
Expand Down
1 change: 1 addition & 0 deletions Documentation/docs-mobile/messages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ Either change the value in the AndroidManifest.xml to match the $(SupportedOSPla
+ [XA4236](xa4236.md): Cannot download Maven artifact '{group}:{artifact}'. - {jar}: {exception} - {aar}: {exception}
+ [XA4237](xa4237.md): Cannot download POM file for Maven artifact '{artifact}'. - Failed to resolve POM for Maven artifact '{dependency}' from '{url}'. - {exception}
+ [XA4239](xa4239.md): Unknown Maven repository: '{repository}'.
+ [XA4240](xa4240.md): The Java callable wrapper code generation target '{0}' is no longer supported. The '_AndroidJcwCodegenTarget' property only supports 'XAJavaInterop1'; 'XamarinAndroid' and 'JavaInterop1' are not supported.
+ [XA4241](xa4241.md): Java dependency '{artifact}' is not satisfied.
+ [XA4242](xa4242.md): Java dependency '{artifact}' is not satisfied. Microsoft maintains the NuGet package '{nugetId}' that could fulfill this dependency.
+ [XA4243](xa4243.md): Attribute '{name}' is required when using '{name}' for '{element}' item '{itemspec}'.
Expand Down
34 changes: 34 additions & 0 deletions Documentation/docs-mobile/messages/xa4240.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: .NET for Android error XA4240
description: XA4240 error code
ms.date: 08/24/2026
f1_keywords:
- "XA4240"
---

# .NET for Android error XA4240

## Example messages

```
error XA4240: The Java callable wrapper code generation target 'XamarinAndroid' is no longer supported. The '_AndroidJcwCodegenTarget' property only supports 'XAJavaInterop1'; 'XamarinAndroid' and 'JavaInterop1' are not supported.
error XA4240: The Java callable wrapper code generation target 'JavaInterop1' is no longer supported. The '_AndroidJcwCodegenTarget' property only supports 'XAJavaInterop1'; 'XamarinAndroid' and 'JavaInterop1' are not supported.
```

## Issue

The project sets the internal `_AndroidJcwCodegenTarget` MSBuild property to
`XamarinAndroid` or `JavaInterop1`. These Java callable wrapper code generation
targets are no longer supported for any .NET for Android runtime.

## Solution

Remove any `_AndroidJcwCodegenTarget` assignment that uses `XamarinAndroid` or
`JavaInterop1`, for example:

```xml
<_AndroidJcwCodegenTarget>JavaInterop1</_AndroidJcwCodegenTarget>
```

The property defaults to `XAJavaInterop1`. If a build customization must set
it explicitly, update the value to `XAJavaInterop1`.
9 changes: 9 additions & 0 deletions src/Mono.Android/Android.Runtime/AndroidRuntimeInternal.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#if INSIDE_MONO_ANDROID_RUNTIME
using System;
using System.Reflection;
using System.Threading;
using Microsoft.Android.Runtime;

namespace Android.Runtime
{
public static class AndroidRuntimeInternal
{
internal static readonly Action<Exception> mono_unhandled_exception;
static int bridgeProcessingGeneration;

internal static int BridgeProcessingGeneration => Volatile.Read (ref bridgeProcessingGeneration);

#pragma warning disable CS0649 // Field is never assigned to. This field is assigned from monodroid-glue.cc.
internal static volatile bool BridgeProcessing; // = false
Expand Down Expand Up @@ -40,6 +44,11 @@ static void MonoUnhandledException (Exception ex)
RuntimeNativeMethods.monodroid_debugger_unhandled_exception (ex);
}

internal static void NotifyBridgeProcessingFinished ()
{
Interlocked.Increment (ref bridgeProcessingGeneration);
}

public static void WaitForBridgeProcessing ()
{
Java.Interop.JniEnvironment.Runtime.ValueManager.WaitForGCBridgeProcessing ();
Expand Down
5 changes: 5 additions & 0 deletions src/Mono.Android/Android.Runtime/JNIEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ public static void WaitForBridgeProcessing ()
JniEnvironment.Runtime.ValueManager.WaitForGCBridgeProcessing ();
}

/// <summary>
/// Gets the number of completed CoreCLR or NativeAOT GC bridge processing cycles.
/// </summary>
public static int BridgeProcessingGeneration => AndroidRuntimeInternal.BridgeProcessingGeneration;

public static IntPtr AllocObject (string jniClassName)
{
IntPtr jniClass = JNIEnv.FindClass (jniClassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ static unsafe void BridgeProcessingFinished (MarkCrossReferencesArgs* mcr)
#pragma warning disable CA1416
JavaMarshal.FinishCrossReferenceProcessing (mcr, handlesToFree);
#pragma warning restore CA1416

AndroidRuntimeInternal.NotifyBridgeProcessingFinished ();
}

static unsafe ReadOnlySpan<GCHandle> ProcessCollectedContexts (MarkCrossReferencesArgs* mcr)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
static Android.Runtime.JNIEnv.BridgeProcessingGeneration.get -> int
REMOVED Xamarin.Android.Net.AndroidClientHandler
REMOVED Xamarin.Android.Net.AndroidClientHandler.AndroidClientHandler() -> void
REMOVED Xamarin.Android.Net.AndroidClientHandler.AssertSelf() -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
static Android.Runtime.JNIEnv.BridgeProcessingGeneration.get -> int
REMOVED Xamarin.Android.Net.AndroidClientHandler
REMOVED Xamarin.Android.Net.AndroidClientHandler.AndroidClientHandler() -> void
REMOVED Xamarin.Android.Net.AndroidClientHandler.AssertSelf() -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
static Android.Runtime.JNIEnv.BridgeProcessingGeneration.get -> int
REMOVED Xamarin.Android.Net.AndroidClientHandler
REMOVED Xamarin.Android.Net.AndroidClientHandler.AndroidClientHandler() -> void
REMOVED Xamarin.Android.Net.AndroidClientHandler.AssertSelf() -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#nullable enable
Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.get -> bool
Android.App.ApplicationAttribute.EnableOnBackInvokedCallback.set -> void
static Android.Runtime.JNIEnv.BridgeProcessingGeneration.get -> int
Original file line number Diff line number Diff line change
Expand Up @@ -4349,6 +4349,7 @@ static Android.Ranging.Wifi.PD.WifiPdRangingCapabilities.Creator.get -> Android.
static Android.Ranging.Wifi.PD.WifiPdRangingParams.Creator.get -> Android.OS.IParcelableCreator!
static Android.Ranging.Wifi.Rtt.RttStationRangingParams.Creator.get -> Android.OS.IParcelableCreator!
static Android.Ranging.Wifi.Rtt.WifiRttSpecificData.Creator.get -> Android.OS.IParcelableCreator!
static Android.Runtime.JNIEnv.BridgeProcessingGeneration.get -> int
static Android.Runtime.JNIEnv.GetClassNameFromInstance(nint jobject) -> string?
static Android.Security.NetworkSecurityPolicy.Instance.get -> Android.Security.NetworkSecurityPolicy!
static Android.Service.Chooser.ChooserSessionToken.Creator.get -> Android.OS.IParcelableCreator!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<!-- jar2xml is not supported -->
<AndroidClassParser>class-parse</AndroidClassParser>
<AndroidCodegenTarget Condition=" '$(AndroidCodegenTarget)' == '' ">XAJavaInterop1</AndroidCodegenTarget>
<_AndroidJcwCodegenTarget Condition=" '$(_AndroidJcwCodegenTarget)' == '' and '$(_AndroidRuntime)' != 'NativeAOT' ">XAJavaInterop1</_AndroidJcwCodegenTarget>
<_AndroidJcwCodegenTarget Condition=" '$(_AndroidJcwCodegenTarget)' == '' ">XAJavaInterop1</_AndroidJcwCodegenTarget>
Comment thread
simonrozsival marked this conversation as resolved.
<AndroidTypeMapImplementation Condition=" '$(AndroidTypeMapImplementation)' == '' and '$(PublishAot)' == 'true' ">trimmable</AndroidTypeMapImplementation>
<AndroidBoundInterfacesContainStaticAndDefaultInterfaceMethods Condition=" '$(AndroidBoundInterfacesContainStaticAndDefaultInterfaceMethods)' == '' ">true</AndroidBoundInterfacesContainStaticAndDefaultInterfaceMethods>
<AndroidBoundInterfacesContainTypes Condition=" '$(AndroidBoundInterfacesContainTypes)' == '' ">true</AndroidBoundInterfacesContainTypes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android.
<PropertyGroup>
<_AndroidRuntimePackRuntime>NativeAOT</_AndroidRuntimePackRuntime>
<_AndroidUseWorkloadNativeLinker Condition=" '$(_AndroidUseWorkloadNativeLinker)' == '' ">true</_AndroidUseWorkloadNativeLinker>
<_AndroidJcwCodegenTarget Condition=" '$(_AndroidJcwCodegenTarget)' == '' ">JavaInterop1</_AndroidJcwCodegenTarget>
<AndroidTypeMapImplementation Condition=" '$(AndroidTypeMapImplementation)' == '' ">trimmable</AndroidTypeMapImplementation>
<!-- .NET SDK gives: error NETSDK1191: A runtime identifier for the property 'PublishAot' couldn't be inferred. Specify a rid explicitly. -->
<AllowPublishAotWithoutRuntimeIdentifier Condition=" '$(AllowPublishAotWithoutRuntimeIdentifier)' == '' ">true</AllowPublishAotWithoutRuntimeIdentifier>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,11 @@ To use a custom JDK path for a command line build, set the 'JavaSdkDirectory' MS
<value>Unknown Maven repository: '{0}'.</value>
<comment>The following are literal names and should not be translated: Maven
{0} - User supplied Maven repository type</comment>
</data>
<data name="XA4240" xml:space="preserve">
<value>The Java callable wrapper code generation target '{0}' is no longer supported. The '_AndroidJcwCodegenTarget' property only supports 'XAJavaInterop1'; 'XamarinAndroid' and 'JavaInterop1' are not supported.</value>
<comment>The following are literal names and should not be translated: _AndroidJcwCodegenTarget, XAJavaInterop1, XamarinAndroid, JavaInterop1
{0} - The name of the current Java callable wrapper code generation target</comment>
</data>
<data name="XA1038" xml:space="preserve">
<value>The '{0}' MSBuild property has an invalid value of '{1}'. A valid value is one of: {2}.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,27 @@ public void XA0119AAB ()
}
}

[Test]
public void UnsupportedJcwCodegenTargetIsRejected (
[Values ("XamarinAndroid", "JavaInterop1")] string codegenTarget,
[Values (AndroidRuntime.MonoVM, AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime)
{
var project = new XamarinAndroidApplicationProject {
IsRelease = runtime == AndroidRuntime.NativeAOT,
};
if (runtime == AndroidRuntime.MonoVM) {
project.SetProperty ("_DisableCheckForUnsupportedMonoMobileRuntime", "true");
}
project.SetRuntime (runtime);
project.SetProperty ("_AndroidJcwCodegenTarget", codegenTarget);
using (var builder = CreateApkBuilder ()) {
builder.Target = "_CheckForInvalidConfigurationAndPlatform";
builder.ThrowOnBuildFailure = false;
Assert.IsFalse (builder.Build (project), "Build should have failed.");
StringAssertEx.Contains ("error XA4240:", builder.LastBuildOutput, "Build should fail with XA4240.");
StringAssertEx.Contains (codegenTarget, builder.LastBuildOutput, "Error should identify the unsupported code generation target.");
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"Size": 3124
},
"classes.dex": {
"Size": 22804
"Size": 404664
},
"lib/arm64-v8a/libUnnamedProject.so": {
"Size": 5747648
"Size": 5731688
},
"res/drawable-hdpi-v4/icon.png": {
"Size": 2178
Expand All @@ -35,5 +35,5 @@
"Size": 1904
}
},
"PackageSize": 2401051
"PackageSize": 2474779
}
Original file line number Diff line number Diff line change
Expand Up @@ -3042,6 +3042,14 @@ because xbuild doesn't support framework reference assemblies.

<Import Project="$(MSBuildThisFileDirectory)Xamarin.Installer.Common.targets"
Condition=" '$(DesignTimeBuild)' != 'true' "/>
<Target Name="_ValidateAndroidJcwCodegenTarget"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform">
<AndroidError Code="XA4240"
ResourceName="XA4240"
FormatArguments="$(_AndroidJcwCodegenTarget)"
Condition=" '$(_AndroidJcwCodegenTarget)' == 'XamarinAndroid' or '$(_AndroidJcwCodegenTarget)' == 'JavaInterop1' " />
Comment thread
simonrozsival marked this conversation as resolved.
</Target>

<Target Name="_ValidateAndroidTypeMapImplementation"
BeforeTargets="_CheckForInvalidConfigurationAndPlatform">
<Error Condition=" '$(AndroidTypeMapImplementation)' != '' and '$(AndroidTypeMapImplementation)' != 'llvm-ir' and '$(AndroidTypeMapImplementation)' != 'trimmable' "
Expand Down
Loading
Loading