-
Notifications
You must be signed in to change notification settings - Fork 551
[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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4598967
to
663eaa5
Compare
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
fb618cb
to
d73db9d
Compare
pjcollins
approved these changes
Jun 9, 2022
jonathanpeppers
approved these changes
Jun 9, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
create-android-api
to buildJNIEnv.g.cs
only once, since it is not TargetFramework dependent. Prevents sharing violation when multipleMono.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 onXamarin.Android.Build.Tasks.csproj
so thatXamarin.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]
jnienv-gen.csproj
fromJava.Interop-MonoAndroid.csproj
. This ensuresjnienv-gen.exe
is available when buildingJava.Interop-MonoAndroid.csproj
.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.
andThe file lock is held by a different Gradle process.