From 20d6bcbf1146a6401467053839ef01eeea8089fa Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Tue, 7 Dec 2021 12:31:33 -0500 Subject: [PATCH 1/4] [Java.Interop] JavaTypeParametersAttribute only in net6 Context: https://github.com/xamarin/xamarin-android/pull/6549 When attempting to bump xamarin-android to use bc5bcf4f, the build failed because bc5bcf4f added a "duplicate" type `Java.Interop.JavaTypeParametersAttribute`: error CS0433: The type 'JavaTypeParametersAttribute' exists in both 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' and 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065'. The plan was to use type forwarders for this type from `Mono.Android.dll` to `Java.Interop.dll`, but in retrospect this sounds like a potential "forward-incompatible ABI break" (e56a8c8e) as assemblies built against the newer `Mono.Android.dll` (with type forwarders) won't be usable on previous Xamarin.Android SDKs. Make `JavaTypeParametersAttribute` conditional on `NET`, so that it's only included in .NET 6 builds. .NET SDK for Android will then use type forwarders, which won't be an issue as there's no previous .NET release to be forward compatible with. Update `tests/generator-Tests` so that `JavaTypeParametersAttribute` is once again provided for non-`NET` builds. --- .../JavaTypeParametersAttribute.cs | 4 ++++ .../Integration-Tests/Compiler.cs | 3 +++ .../JavaTypeParametersAttribute.cs | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 tests/generator-Tests/SupportFiles/JavaTypeParametersAttribute.cs diff --git a/src/Java.Interop/Java.Interop/JavaTypeParametersAttribute.cs b/src/Java.Interop/Java.Interop/JavaTypeParametersAttribute.cs index a482636b1..735a19251 100644 --- a/src/Java.Interop/Java.Interop/JavaTypeParametersAttribute.cs +++ b/src/Java.Interop/Java.Interop/JavaTypeParametersAttribute.cs @@ -1,5 +1,7 @@ using System; +#if NET + namespace Java.Interop { [AttributeUsage (AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Method, @@ -14,3 +16,5 @@ public JavaTypeParametersAttribute (string [] typeParameters) public string [] TypeParameters { get; } } } + +#endif // NET diff --git a/tests/generator-Tests/Integration-Tests/Compiler.cs b/tests/generator-Tests/Integration-Tests/Compiler.cs index b49f94e3e..b0386cf9a 100644 --- a/tests/generator-Tests/Integration-Tests/Compiler.cs +++ b/tests/generator-Tests/Integration-Tests/Compiler.cs @@ -40,6 +40,9 @@ public static Assembly Compile (Xamarin.Android.Binder.CodeGeneratorOptions opti if (options.CodeGenerationTarget == CodeGenerationTarget.JavaInterop1) { preprocessorSymbols.Add ("JAVA_INTEROP1"); } +#if NET + preprocessorSymbols.Add ("NET"); +#endif // NET var parseOptions = new CSharpParseOptions (preprocessorSymbols:preprocessorSymbols); diff --git a/tests/generator-Tests/SupportFiles/JavaTypeParametersAttribute.cs b/tests/generator-Tests/SupportFiles/JavaTypeParametersAttribute.cs new file mode 100644 index 000000000..3f25e0b93 --- /dev/null +++ b/tests/generator-Tests/SupportFiles/JavaTypeParametersAttribute.cs @@ -0,0 +1,18 @@ +#if !NET + +using System; + +namespace Java.Interop +{ + public class JavaTypeParametersAttribute : Attribute + { + public JavaTypeParametersAttribute (string [] typeParameters) + { + TypeParameters = typeParameters; + } + + public string [] TypeParameters { get; set; } + } +} + +#endif // !NET From e66b80380f8a6a1440526735781a6bd5d2ed6ac2 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 8 Dec 2021 10:53:19 -0500 Subject: [PATCH 2/4] Fix the VS2019 build. xamarin-android Windows PR builds can't build, because of: error CS8032: An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\6.0.0\analyzers\dotnet\cs\System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. [C:\a\_work\1\s\external\Java.Interop\build-tools\jnienv-gen\jnienv-gen.csproj] Ignore the CS8032 warning/error, so that xamarin-android Windows PR builds can *build*. --- Directory.Build.props | 14 ++++++++++++++ src/Java.Interop/Java.Interop-MonoAndroid.csproj | 2 +- src/Java.Interop/Java.Interop.csproj | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 38044c099..fbd99082a 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -91,6 +91,20 @@ <_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(Runtime) "$(_JNIEnvGenPath)" + + + $(NoWarn);CS8032 + + AllEnabledByDefault diff --git a/src/Java.Interop/Java.Interop-MonoAndroid.csproj b/src/Java.Interop/Java.Interop-MonoAndroid.csproj index 4aaf58ba6..ef9875bb1 100644 --- a/src/Java.Interop/Java.Interop-MonoAndroid.csproj +++ b/src/Java.Interop/Java.Interop-MonoAndroid.csproj @@ -11,7 +11,7 @@ Java.Interop Java.Interop v4.5 - 1591 + $(NoWarn);1591 true ..\..\product.snk 8.0 diff --git a/src/Java.Interop/Java.Interop.csproj b/src/Java.Interop/Java.Interop.csproj index ee91dd585..1ee9e3c10 100644 --- a/src/Java.Interop/Java.Interop.csproj +++ b/src/Java.Interop/Java.Interop.csproj @@ -17,7 +17,7 @@ netstandard2.0;net6.0 - 1591 + $(NoWarn);1591 true ..\..\product.snk INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES;$(JavaInteropDefineConstants) From e9cabedc8cd114350809a32554c4533ac6b0255d Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 8 Dec 2021 16:56:06 -0500 Subject: [PATCH 3/4] Look for class-parse & generator from the right dir Fixes Windows build failure: > C:\Users\cloudtest\android-toolchain\dotnet\dotnet "C:\a\_work\1\s\external\Java.Interop\bin\Release-net6.0\class-parse.dll" "C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\11.0.13-8\x64/jmods/java.base.jmod" "-o=obj\\Release-net6.0\/mcw/api.xml" Could not execute because the specified command or file was not found. Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a .NET program, but dotnet-C:\a\_work\1\s\external\Java.Interop\bin\Release-net6.0\class-parse.dll does not exist. * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH. This is because `Java.Base.targets` should have been using `$(UtilityOutputFullPath)`, not `$(ToolOutputFullPath)`. Doh! --- src/Java.Base/Java.Base.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Java.Base/Java.Base.targets b/src/Java.Base/Java.Base.targets index 2bb3d9ccd..bf23f6dde 100644 --- a/src/Java.Base/Java.Base.targets +++ b/src/Java.Base/Java.Base.targets @@ -1,7 +1,7 @@  - $(ToolOutputFullPath)generator.dll + $(UtilityOutputFullPath)generator.dll @@ -17,7 +17,7 @@ Outputs="$(IntermediateOutputPath)\mcw\api.xml"> - <_ClassParse>"$(ToolOutputFullPath)class-parse.dll" + <_ClassParse>"$(UtilityOutputFullPath)class-parse.dll" <_Input>"$(_JavaBaseJmod)" <_Output>"-o=$(IntermediateOutputPath)/mcw/api.xml" From cc7c53c3f56864300556c7ef1d9cc64f21992b33 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Wed, 8 Dec 2021 18:19:49 -0500 Subject: [PATCH 4/4] More VS2019 fixes; Need to always import $(NoWarn) --- src/Java.Base/Java.Base.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Java.Base/Java.Base.csproj b/src/Java.Base/Java.Base.csproj index b9728073b..5be4deceb 100644 --- a/src/Java.Base/Java.Base.csproj +++ b/src/Java.Base/Java.Base.csproj @@ -4,7 +4,7 @@ net6.0 true enable - 8764 + $(NoWarn);8764