Skip to content

Test https://github.com/xamarin/java.interop/pull/1199 #8751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from

Conversation

jonathanpeppers
Copy link
Member

No description provided.

@jonpryor
Copy link
Contributor

These test failures are disturbing;

https://github.com/xamarin/xamarin-android/blob/0665f449948c43675ec8706a5a2807b5d3f599f7/tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs#L178-L186

is failing

Java.Lang.ClassNotFoundException : crc64d04135c992393d83.Type
----> Java.Lang.ClassNotFoundException : Didn't find class "crc64d04135c992393d83.Type" on path: DexPathList[[zip file "/data/app/Mono.Android.NET_Tests-b_m3H0at1u7QzB7wf38hoQ==/base.apk", zip file "/data/app/Mono.Android.NET_Tests-b_m3H0at1u7QzB7wf38hoQ==/split_config.x86_64.apk", zip file "/data/app/Mono.Android.NET_Tests-b_m3H0at1u7QzB7wf38hoQ==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/Mono.Android.NET_Tests-b_m3H0at1u7QzB7wf38hoQ==/lib/x86_64, /data/app/Mono.Android.NET_Tests-b_m3H0at1u7QzB7wf38hoQ==/base.apk!/lib/x86_64, /data/app/Mono.Android.NET_Tests-b_m3H0at1u7QzB7wf38hoQ==/split_config.x86_64.apk!/lib/x86_64, /data/app/Mono.Android.NET_Tests-b_m3H0at1u7QzB7wf38hoQ==/split_config.xxhdpi.apk!/lib/x86_64, /system/lib64, /system/product/lib64]]

I'm reminded of the typemap snafu in #8478 (comment), which doesn't make immediate sense to me.

@jonathanpeppers
Copy link
Member Author

Yes, the test failures are somehow caused by: dotnet/java-interop@56b7eeb

But this fixed the build errors now.

@jonathanpeppers jonathanpeppers changed the title Test https://github.com/xamarin/java.interop/pull/1197 Test https://github.com/xamarin/java.interop/pull/1198 Feb 23, 2024
@jonpryor
Copy link
Contributor

The Windows build failure is weird:

         CSC : error CS1705: Assembly 'Java.Interop.Tools.JavaCallableWrappers' with identity 'Java.Interop.Tools.JavaCallableWrappers, Version=7.0.0.157, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' uses 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' [C:\a\_work\1\s\src\Xamarin.Android.Build.Tasks\Xamarin.Android.Build.Tasks.csproj]

jonpryor pushed a commit to dotnet/java-interop that referenced this pull request Feb 24, 2024
Context: dotnet/android#8751
Context: 56b7eeb
Context: 67c079c

dotnet/android#8751 attempts to figure out how Java.Interop
broke xamarin-android.  That investigation eventually resulted in
67c079c, which allowed xamarin-android to *build* again, and
uncovered a unit test failure.

[`JnienvTest.NewObjectArrayWithNonJavaTypeAndEmptyArray()`][0]:

	[Test]
	public void NewObjectArrayWithNonJavaTypeAndEmptyArray ()
	{
	    //empty array gives the right type
	    var array = JNIEnv.NewObjectArray<Type> (new Type [0]);
	    …
	}

started failing:

	Java.Lang.ClassNotFoundException : crc64d04135c992393d83.Type
	----> Java.Lang.ClassNotFoundException : Didn't find class "crc64d04135c992393d83.Type" on path: DexPathList[[zip file "/data/app/Mono.Android.NET_Tests-VrfrXDHT2r32zDG95kFOiw==/base.apk", zip file "/data/app/Mono.Android.NET_Tests-VrfrXDHT2r32zDG95kFOiw==/split_config.x86_64.apk", zip file "/data/app/Mono.Android.NET_Tests-VrfrXDHT2r32zDG95kFOiw==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/Mono.Android.NET_Tests-VrfrXDHT2r32zDG95kFOiw==/lib/x86_64, /data/app/Mono.Android.NET_Tests-VrfrXDHT2r32zDG95kFOiw==/base.apk!/lib/x86_64, /data/app/Mono.Android.NET_Tests-VrfrXDHT2r32zDG95kFOiw==/split_config.x86_64.apk!/lib/x86_64, /data/app/Mono.Android.NET_Tests-VrfrXDHT2r32zDG95kFOiw==/split_config.xxhdpi.apk!/lib/x86_64, /system/lib64, /system/product/lib64]]

It turns out, this type is completely wrong?  It should be looking
for `java/lang/Object` instead?

In 56b7eeb, we lost an important detail from the expression:

	// 56b7eeb^
	if (!type.GetInterfaces ().Any (t => t.FullName == "Android.Runtime.IJavaObject")) …

	// 56b7eeb equivalent:
	if (type.GetInterfaces ().Any (t => t.FullName == "Java.Interop.IJavaPeerable")) …

We are missing the `!` !!!

I was able to reproduce this behavior in a test:

	[Test]
	[TestCase (typeof (System.Type), "java/lang/Object")]
	public void ToJniName (Type type, string expected)
	{
	    string actual = JavaNativeTypeManager.ToJniName (type);
	    Assert.AreEqual (expected, actual);
	}

Where `ToJniName()` was returning `crc64d04135c992393d83/Type` instead
of `java/lang/Object`!

After fixing the problem, the test passes.

[0]: https://github.com/xamarin/xamarin-android/blob/0665f449948c43675ec8706a5a2807b5d3f599f7/tests/Mono.Android-Tests/Java.Interop/JnienvTest.cs#L178-L186
@jonathanpeppers jonathanpeppers changed the title Test https://github.com/xamarin/java.interop/pull/1198 Test https://github.com/xamarin/java.interop/pull/1199 Feb 26, 2024
jonpryor pushed a commit to dotnet/java-interop that referenced this pull request Feb 27, 2024
…1199)

Context: dotnet/android#8751
Context: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=9137456&view=logs&j=96fd57f5-f69e-53c7-3d47-f67e6cf9b93e&s=1afc3bfe-122c-538b-e9ad-2a86c2efcfef&t=38f83f46-bc21-5edd-1614-e44f20babf10&l=29658
Context: 67c079c
Context: 56b7eeb

dotnet/android#8751 has a random build failure:

	"Xamarin.Android.sln" (default target) (1:2) ->
	"src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj" (default target) (28:9) ->
	(CoreCompile target) ->
	    src/Xamarin.Android.Build.Tasks/Utilities/MamJsonParser.cs(92,43): error CS0122: 'NotNullWhenAttribute' is inaccessible due to its protection level [src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj]
	    src/Xamarin.Android.Build.Tasks/Utilities/MamJsonParser.cs(92,81): error CS0122: 'NotNullWhenAttribute' is inaccessible due to its protection level [src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj]
	    src/Xamarin.Android.Build.Tasks/Utilities/MavenExtensions.cs(26,32): error CS0122: 'NotNullWhenAttribute' is inaccessible due to its protection level [src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj]

It happens some percentage of the time…

Similar to 67c079c, the cause is that commit 56b7eeb updated
`Java.Interop.Tools.JavaCallableWrappers.csproj` to multitarget both
netstandard2.0 and net8.0, and on some builds the
`Java.Interop.Tools.JavaCallableWrappers.dll` used by
`Xamarin.Android.Build.Tasks.csproj` is the net8.0 build, *not* the
netstandard2.0 build.

To fix this:

  * Don't build `Java.Interop.Tools.JavaCallableWrappers.csproj` for
    `net8.0` anymore; remove net8.0 from `$(TargetFrameworks)`.

  * Introduce a new `Java.Interop.Tools.TypeNameMappings.csproj`
    project which builds the source code within
    `Java.Interop.Tools.JavaCallableWrappers.csproj` for net8.0.
    The resulting assembly is not shipped or used.  It can check
    trimmer warnings, though.

This partially reverts 67c079c and 56b7eeb.
@jonathanpeppers
Copy link
Member Author

Closing in favor of #8766

@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants