Skip to content

Conversation

@jonpryor
Copy link
Contributor

Commit 9d131af introduced a unit test failure on
xamarin-android/master:

Xamarin.Android.Build.Tests.BuildTest.XA4212
Expected: String containing "warning XA4"
 But was: <log file contents...>

Aside: The XA4212 test creates a project with a bad IJavaObject
type, builds the project -- which triggers an XA4212 error, which is
observed in the unit test -- then rebuilds the project, but this
time with $(AndroidErrorOnCustomJavaObject)=False.

The intention is that the second build should instead elicit an XA4212
warning, but otherwise continue just fine.

What's interesting about the log file contents is that it shows that
the <GenerateJavaStubs/> task isn't executed at all, but it's the
<GenerateJavaStubs/> task which is supposed to emit the warning!

Skipping target "_GenerateJavaStubs" because its outputs are up-to-date.

Update the <GenerateJavaStubs/> task so that if it errors out, it
removes any <GenerateJavaStubs/> output files. This will ensure
that on subsequent builds, the _GenerateJavaStubs target won't be
inadvertently skipped.

(This issue should have been caught during the
macOS+xbuild PR builder build for PR #797. It wasn't,
because the Xamarin.Android.Build.Tests tests weren't reported. For
example, PR #1491 ran 869 tests, while PR #1492 ran 1085! I'm not sure
what can be done to better detect and prevent this in the future.)

Commit 9d131af introduced a [unit test failure][m573] on
xamarin-android/master:

[m573]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/573/

	Xamarin.Android.Build.Tests.BuildTest.XA4212
	Expected: String containing "warning XA4"
	 But was: <log file contents...>

Aside: The XA4212 test creates a project with a bad `IJavaObject`
type, builds the project -- which triggers an XA4212 error, which *is*
observed in the unit test -- then *rebuilds* the project, but this
time with `$(AndroidErrorOnCustomJavaObject)`=False.

The intention is that the second build should instead elicit an XA4212
*warning*, but otherwise continue just fine.

What's interesting about the log file contents is that it shows that
the `<GenerateJavaStubs/>` task isn't executed *at all*, but it's the
`<GenerateJavaStubs/>` task which is supposed to emit the warning!

	Skipping target "_GenerateJavaStubs" because its outputs are up-to-date.

Update the `<GenerateJavaStubs/>` task so that if it errors out, it
*removes* any `<GenerateJavaStubs/>` output files. This will ensure
that on subsequent builds, the `_GenerateJavaStubs` target won't be
inadvertently skipped.

(This issue *should* have been caught during the
[**macOS+xbuild PR builder** build for PR dotnet#797][pr1491]. It *wasn't*,
because the `Xamarin.Android.Build.Tests` tests weren't reported. For
example, PR dotnet#1491 ran 869 tests, while PR dotnet#1492 ran 1085! I'm not sure
what can be done to better detect and prevent this in the future.)

[pr1491]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-pr-builder/1491/
@dellis1972 dellis1972 merged commit b8dc732 into dotnet:master Aug 31, 2017
@djversoza
Copy link

I received a few updates in Visual Studio Community for Mac, and after updating I've been receiving error XA4212 when trying to build an android app. The app was working fine before updating and now I'm unable to build.
screen shot 2017-12-05 at 2 30 26 pm

@jonpryor
Copy link
Contributor Author

jonpryor commented Dec 5, 2017

The app may have been working fine, but it was using a erroneous code pattern: somewhere in your code, you were implement IJavaObject:

class BadExample : IJavaObject {
    public IntPtr Handle {
        get {return IntPtr.Zero;}
    }
    public void Dispose()
    {
    }
}

This is erroneous because it means that when you pass instances of Example into Java, you're actually passing null. This may or may not break anything, but it's certainly not what anybody expects or intends.

Instead, code should subclass Java.Lang.Object to implement IJavaObject:

class CorrectExample : Java.Lang.Object {
}

You should correct your JobServiceEngineImpl type to inherit from Java.Lang.Object.

If you just want to get your code compiling again, you can set the $(AndroidErrorOnCustomJavaObject) MSBuild property to False.

<!-- Within your App.csproj, near the top, add: -->
<PropertyGroup>
  <AndroidErrorOnCustomJavaObject>False</AndroidErrorOnCustomJavaObject>
</PropertyGroup>

@github-actions github-actions bot locked and limited conversation to collaborators Feb 5, 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.

4 participants