Skip to content

Commit 51c3dae

Browse files
authored
[Java.Interop-MonoAndroid.csproj] Add jnienv-gen ProjectReference (#990)
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
1 parent d0ef9e3 commit 51c3dae

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Java.Interop/Java.Interop-MonoAndroid.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
4+
<PropertyGroup Condition=" '$(XAInstallPrefix)' != '' ">
5+
<TargetFrameworkIdentifier>MonoAndroid</TargetFrameworkIdentifier>
6+
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
7+
<TargetFrameworkRootPath>$(XAInstallPrefix)xbuild-frameworks</TargetFrameworkRootPath>
8+
</PropertyGroup>
9+
310
<PropertyGroup>
411
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
512
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -113,5 +120,10 @@
113120
<None Include="Documentation\Java.Interop\IJavaPeerable.xml" />
114121
<None Include="Documentation\Java.Interop\JniManagedPeerStates.xml" />
115122
<None Include="Documentation\Java.Interop\JniEnvironment.References.xml" />
123+
<ProjectReference Include="..\..\build-tools\jnienv-gen\jnienv-gen.csproj"
124+
ReferenceOutputAssembly="false"
125+
SkipGetTargetFrameworkProperties="True"
126+
AdditionalProperties="TargetFramework=net472"
127+
/>
116128
</ItemGroup>
117129
</Project>

0 commit comments

Comments
 (0)