Skip to content

[Xamarin.Android.sln] Fix issues preventing parallel builds. #7068

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

Merged
merged 3 commits into from
Jun 14, 2022

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Jun 3, 2022

There are several known issues that cause errors when attempting to dotnet build Xamarin.Android.sln without -m:1. With these fixes, the build seems to be buildable without -m:1.

Testing conducted is 4 consecutive CI builds without errors. Note that due to the unpredictability of race-condition errors appearing, this is not a guarantee that all issues are fixed. We will simply have to run with this and fix any additional errors as they appear.

Fixes:

  • Use create-android-api to build JNIEnv.g.cs only once, since it is not TargetFramework dependent. Prevents sharing violation when multiple Mono.Android.csproj builds attempt to create it simultaneously.
    • System.IO.IOException: The process cannot access the file 'C:\a\_work\1\s\src\Mono.Android\Android.Runtime\JNIEnv.g.cs' because it is being used by another process.
  • Microsoft.Android.Sdk.ILLink.csproj needs a dependency on Xamarin.Android.Build.Tasks.csproj so that Xamarin.Android.Build.Tasks\obj\$(Configuration)\Profile.g.cs is available for compile.
    • CSC error CS2001: Source file 'C:\code\xamarin-android\src\Microsoft.Android.Sdk.ILLink\..\Xamarin.Android.Build.Tasks\obj\Debug\Profile.g.cs' could not be found. [C:\code\xamarin-android\src\Microsoft.Android.Sdk.ILLink\Microsoft.Android.Sdk.ILLink.csproj]
  • Add a project reference to jnienv-gen.csproj from Java.Interop-MonoAndroid.csproj. This ensures jnienv-gen.exe is available when building Java.Interop-MonoAndroid.csproj.
  • Add project references between apksigner/r8/manifestmerger. gradlew hits an issue when running multiple copies simultaneously. While there isn't an actual dependency between these, it forces them to build sequentially.
    • org.gradle.launcher.daemon.client.DaemonConnectionException: Timeout waiting to connect to the Gradle daemon. and The file lock is held by a different Gradle process.

@jpobst jpobst force-pushed the parallel-fixes branch 7 times, most recently from 4598967 to 663eaa5 Compare June 7, 2022 14:39
jonpryor pushed a commit to dotnet/java-interop that referenced this pull request Jun 8, 2022
Context: dotnet/android#7068

When attempting to build xamarin/xamarin-android *without* using
`dotnet build -m:1` -- *with* parallel builds enabled -- the build
can randomly fail:

	'"C:\a\_work\1\s\external\Java.Interop\bin\BuildRelease\jnienv-gen.exe"' is not recognized as an internal or external command, operable program or batch file.

or

	…/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop.targets(19,5):
	error MSB3073: The command "mono "…/xamarin-android/external/Java.Interop/bin/BuildDebug/jnienv-gen.exe" Java.Interop/JniEnvironment.g.cs obj/Debug/jni.c" exited with code 2.
	[…/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop-MonoAndroid.csproj]

The cause of the error is that xamarin-android's `Mono.Android.targets`
[uses `<MSBuild/>` to build `Java.Interop-MonoAndroid.csproj`][0],
and `Java.Interop-MonoAndroid.csproj` does not have a
`@(ProjectReference)` to `build-tools/jnienv-gen/jnienv-gen.csproj`.
Consequently, when `Java.Interop-MonoAndroid.csproj` is built,
`jnienv-gen.exe` *may not exist*, resulting in the MSB3073 errors.

Fix this usage scenario by updating `Java.Interop-MonoAndroid.csproj`
to have a `@(ProjectReference)` to
`build-tools/jnienv-gen/jnienv-gen.csproj`.  This ensures that
`jnienv-gen.exe` exists before the `BuildJniEnvironment_g_cs` target
in `Java.Interop.targets` is executed.

Additionally, move some of the "property overrides" defined in
`Mono.Android.targets` (for use by `Java.Interop-MonoAndroid.csproj`)
into `Java.Interop-MonoAndroid.csproj`.  The problem with having them
in `Mono.Android.targets` is that the invocation worked as a *global*
override, overriding `$(TargetFrameworkVersion)`/etc. when
*`build-tools/jnienv-gen/jnienv-gen.csproj`* is built, causing the
resulting `jnienv-gen.exe` to possibly be a "monoandroid10" app,
*not* a net472 app.  Moving these properties into
`Java.Interop-MonoAndroid.csproj` means that `Mono.Android.targets`
*doesn't* need to specify them, which means the `jnienv-gen.csproj`
build won't inadvertently use them.

[0]: https://github.com/xamarin/xamarin-android/blob/6b43af37bc57b7eea2a213ee15de037e61784a1c/src/Mono.Android/Mono.Android.targets#L23-L50
@jpobst jpobst force-pushed the parallel-fixes branch 2 times, most recently from fb618cb to d73db9d Compare June 9, 2022 01:55
@jpobst jpobst marked this pull request as ready for review June 9, 2022 14:48
@jpobst jpobst requested review from pjcollins and jonpryor as code owners June 9, 2022 14:48
@jpobst jpobst requested a review from jonathanpeppers June 9, 2022 14:48
@jonpryor jonpryor merged commit 944f88a into main Jun 14, 2022
@jonpryor jonpryor deleted the parallel-fixes branch June 14, 2022 01:02
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 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