Skip to content

Commit 0edc16d

Browse files
[Xamarin.Android.Build.Tasks] introduce $(_AndroidJcwCodegenTarget) (#9858)
Context: #9846 Context: dbb0b92 Context: d70db5b While trying to *build* `tests/Mono.Android-Tests` with NativeAOT: dotnet-local.cmd build tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj ^ -p:TestsFlavor=NativeAOT -p:PublishAot=true -c Release -bl -t:Install it would fail to build: tests\Mono.Android-Tests\Java.Interop-Tests\obj\Release\net10.0-android\generated\src\Net.Dot.Jni.Test.MyJavaInterfaceImpl.cs(19,81): error CS1056: Unexpected character '`' The offending code? public partial class MyJavaInterfaceImpl : global::Java.Interop.JavaObjectArray`1, global::Net.Dot.Jni.Test.IJavaInterface { } which is deeply, *deeply*, wrong. Further investigation showed that the problem was that `Java.Interop-Tests` was trying to bind Java code, and in this case was using `generator --codegen-target=JavaInterop1` output. This is output we've never tried to use before in .NET for Android; `generator --codegen-target=JavaInterop1` is experimental (and @jonpryor's playground; see dotnet/java-interop#858), and shouldn't be used *now* (if ever). Ultimately, we realized that commit d70db5b was *wrong*, in that it merged two different things: 1. Java stub generation's "codegen target", previously settable by an MSBuild property `$(_AndroidCodeGenerationTarget)` (introduced in dbb0b92) 2. C# `generator`s "codegen target" or `$(AndroidCodegenTarget)` The problem was `$(_AndroidCodeGenerationTarget)` was just poorly named making me think it was the same as `$(AndroidCodegenTarget)`. Partially revert d70db5b and use the name `$(_AndroidJcwCodegenTarget)` instead. NativeAOT now defaults to: * `$(_AndroidJcwCodegenTarget)=JavaInterop1` * `$(AndroidCodegenTarget)=XAJavaInterop1`
1 parent dc4f29d commit 0edc16d

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
<!-- Bindings properties -->
4242
<!-- jar2xml is not supported -->
4343
<AndroidClassParser>class-parse</AndroidClassParser>
44-
<AndroidCodegenTarget Condition=" '$(AndroidCodegenTarget)' == '' and '$(_AndroidRuntime)' != 'NativeAOT' ">XAJavaInterop1</AndroidCodegenTarget>
44+
<AndroidCodegenTarget Condition=" '$(AndroidCodegenTarget)' == '' ">XAJavaInterop1</AndroidCodegenTarget>
45+
<_AndroidJcwCodegenTarget Condition=" '$(_AndroidJcwCodegenTarget)' == '' and '$(_AndroidRuntime)' != 'NativeAOT' ">XAJavaInterop1</_AndroidJcwCodegenTarget>
4546
<AndroidBoundInterfacesContainStaticAndDefaultInterfaceMethods Condition=" '$(AndroidBoundInterfacesContainStaticAndDefaultInterfaceMethods)' == '' ">true</AndroidBoundInterfacesContainStaticAndDefaultInterfaceMethods>
4647
<AndroidBoundInterfacesContainTypes Condition=" '$(AndroidBoundInterfacesContainTypes)' == '' ">true</AndroidBoundInterfacesContainTypes>
4748
<AndroidBoundInterfacesContainConstants Condition=" '$(AndroidBoundInterfacesContainConstants)' == '' ">true</AndroidBoundInterfacesContainConstants>

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This file contains the NativeAOT-specific MSBuild logic for .NET for Android.
1212
<!-- Default property values for NativeAOT -->
1313
<PropertyGroup>
1414
<_AndroidRuntimePackRuntime>NativeAOT</_AndroidRuntimePackRuntime>
15-
<AndroidCodegenTarget Condition=" '$(AndroidCodegenTarget)' == '' ">JavaInterop1</AndroidCodegenTarget>
15+
<_AndroidJcwCodegenTarget Condition=" '$(_AndroidJcwCodegenTarget)' == '' ">JavaInterop1</_AndroidJcwCodegenTarget>
1616
<!-- .NET SDK gives: error NETSDK1191: A runtime identifier for the property 'PublishAot' couldn't be inferred. Specify a rid explicitly. -->
1717
<AllowPublishAotWithoutRuntimeIdentifier Condition=" '$(AllowPublishAotWithoutRuntimeIdentifier)' == '' ">true</AllowPublishAotWithoutRuntimeIdentifier>
1818
<!-- NativeAOT's targets currently gives an error about cross-compilation -->

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

+6-6
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ because xbuild doesn't support framework reference assemblies.
13891389
<_AndroidJarAndDexDirectory>$(_XATargetFrameworkDirectories)</_AndroidJarAndDexDirectory>
13901390
</PropertyGroup>
13911391
<GetMonoPlatformJar
1392-
Condition=" '$(_AndroidUseMarshalMethods)' != 'True' and '$(AndroidCodegenTarget)' == 'XAJavaInterop1' "
1392+
Condition=" '$(_AndroidUseMarshalMethods)' != 'True' and '$(_AndroidJcwCodegenTarget)' == 'XAJavaInterop1' "
13931393
TargetFrameworkDirectory="$(_AndroidJarAndDexDirectory)">
13941394
<Output TaskParameter="MonoPlatformJarPath" PropertyName="MonoPlatformJarPath" />
13951395
<Output TaskParameter="MonoPlatformDexPath" PropertyName="MonoPlatformDexPath" />
@@ -1418,12 +1418,12 @@ because xbuild doesn't support framework reference assemblies.
14181418
/>
14191419

14201420
<Copy
1421-
Condition=" '$(_AndroidUseMarshalMethods)' != 'True' and '$(AndroidCodegenTarget)' == 'XAJavaInterop1' "
1421+
Condition=" '$(_AndroidUseMarshalMethods)' != 'True' and '$(_AndroidJcwCodegenTarget)' == 'XAJavaInterop1' "
14221422
SourceFiles="$(MonoPlatformJarPath)"
14231423
DestinationFiles="$(IntermediateOutputPath)android\bin\mono.android.jar"
14241424
SkipUnchangedFiles="true" />
14251425
<Touch
1426-
Condition=" '$(_AndroidUseMarshalMethods)' != 'True' and '$(AndroidCodegenTarget)' == 'XAJavaInterop1' "
1426+
Condition=" '$(_AndroidUseMarshalMethods)' != 'True' and '$(_AndroidJcwCodegenTarget)' == 'XAJavaInterop1' "
14271427
Files="$(IntermediateOutputPath)android\bin\mono.android.jar" />
14281428

14291429
<Touch Files="$(_AndroidStaticResourcesFlag)" AlwaysCreate="true" />
@@ -1433,7 +1433,7 @@ because xbuild doesn't support framework reference assemblies.
14331433
<FileWrites Include="$(_AndroidIntermediateJavaSourceDirectory)mono\JavaInteropTypeManager.java" />
14341434
<FileWrites Include="$(MonoAndroidIntermediateAssemblyDir)machine.config" />
14351435
<FileWrites
1436-
Condition=" '$(_AndroidUseMarshalMethods)' != 'True' and '$(AndroidCodegenTarget)' == 'XAJavaInterop1' "
1436+
Condition=" '$(_AndroidUseMarshalMethods)' != 'True' and '$(_AndroidJcwCodegenTarget)' == 'XAJavaInterop1' "
14371437
Include="$(IntermediateOutputPath)android\bin\mono.android.jar"
14381438
/>
14391439
<FileWrites Include="$(_AndroidStaticResourcesFlag)" />
@@ -1530,7 +1530,7 @@ because xbuild doesn't support framework reference assemblies.
15301530

15311531
<GenerateJavaStubs
15321532
AndroidRuntime="$(_AndroidRuntime)"
1533-
CodeGenerationTarget="$(AndroidCodegenTarget)"
1533+
CodeGenerationTarget="$(_AndroidJcwCodegenTarget)"
15341534
ResolvedAssemblies="@(_ResolvedAssemblies)"
15351535
ResolvedUserAssemblies="@(_ResolvedUserMonoAndroidAssemblies)"
15361536
ErrorOnCustomJavaObject="$(AndroidErrorOnCustomJavaObject)"
@@ -1566,7 +1566,7 @@ because xbuild doesn't support framework reference assemblies.
15661566
ApplicationLabel="$(_ApplicationLabel)"
15671567
BundledWearApplicationName="$(BundledWearApplicationPackageName)"
15681568
CheckedBuild="$(_AndroidCheckedBuild)"
1569-
CodeGenerationTarget="$(AndroidCodegenTarget)"
1569+
CodeGenerationTarget="$(_AndroidJcwCodegenTarget)"
15701570
Debug="$(AndroidIncludeDebugSymbols)"
15711571
EmbedAssemblies="$(EmbedAssembliesIntoApk)"
15721572
EnableMarshalMethods="$(_AndroidUseMarshalMethods)"

0 commit comments

Comments
 (0)