Skip to content

Commit d70e40f

Browse files
authored
[Java.Interop, jnienv-gen] Add netcoreapp3.1 support (#614)
`Java.Interop.dll` is already a .NET Standard 2.0 library, which is already compatible with .NETCoreApp,Version=3.1. Why does it need to be built against `netcoreapp3.1` framework? Consistent Assembly References. `Java.Interop.dll` was originally a PCL, and before it became a .NET Standard 2.0 library in commit 85be94f, we added support to build `Java.Interop.dll` as a `MonoAndroid`-profile assembly in commit 893562c, as doing so reduced the assemblies referenced from the PCL version from 15 assemblies (`System.Runtime`, `System.Collections`, …) down to *3* assemblies: `mscorlib`, `System`, `System.Core`. Reducing the number of assemblies referenced improved build and deploy times. In the .NET Standard 2.0 world order, `Java.Interop.dll` now has *one* assembly reference: `netstandard`. However, within Xamarin.Android, `netstandard.dll` has 16 assembly references (as of mono/2020-02), which *might* matter, but very likely doesn't matter *that* much, as any large app will probably be pulling in .NET Standard libraries anyway. Why add `netcoreapp3.1` support to `Java.Interop.csproj`? While it's not strictly *needed*, it does increase consistency, replacing the `netstandard` assembly reference with "real" references which will be consistent with the [equivalent `Mono.Android.dll`][0]. To build `Java.Interop.dll` for `netcoreapp3.1`, also begin building `jnienv-gen` for netcoreapp3.1, and add the appropriate build system voodoo so that it can be executed. [0]: dotnet/android@e2854ee
1 parent 56c92c7 commit d70e40f

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

Directory.Build.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
Condition="Exists('$(_OutputPath)MonoInfo.props')"
1919
/>
2020
<PropertyGroup Condition=" '$(TargetFramework)' != '' And $(TargetFramework.StartsWith ('netcoreapp')) ">
21+
<JIBuildingForNetCoreApp>True</JIBuildingForNetCoreApp>
22+
</PropertyGroup>
23+
<PropertyGroup Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">
2124
<BuildToolOutputFullPath>$(MSBuildThisFileDirectory)bin\Build$(Configuration)-$(TargetFramework)\</BuildToolOutputFullPath>
2225
<ToolOutputFullPath>$(MSBuildThisFileDirectory)bin\$(Configuration)-$(TargetFramework)\</ToolOutputFullPath>
2326
<TestOutputFullPath>$(MSBuildThisFileDirectory)bin\Test$(Configuration)-$(TargetFramework)\</TestOutputFullPath>
2427
<UtilityOutputFullPath Condition=" '$(UtilityOutputFullPathCoreApps)' != '' ">$(UtilityOutputFullPathCoreApps)</UtilityOutputFullPath>
2528
<UtilityOutputFullPath Condition=" '$(UtilityOutputFullPathCoreApps)' == '' ">$(ToolOutputFullPath)</UtilityOutputFullPath>
2629
</PropertyGroup>
27-
<PropertyGroup Condition=" '$(TargetFramework)' == '' Or !$(TargetFramework.StartsWith ('netcoreapp')) ">
30+
<PropertyGroup Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">
2831
<BuildToolOutputFullPath>$(MSBuildThisFileDirectory)bin\Build$(Configuration)\</BuildToolOutputFullPath>
2932
<ToolOutputFullPath>$(MSBuildThisFileDirectory)bin\$(Configuration)\</ToolOutputFullPath>
3033
<TestOutputFullPath>$(MSBuildThisFileDirectory)bin\Test$(Configuration)\</TestOutputFullPath>

build-tools/jnienv-gen/jnienv-gen.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net472</TargetFramework>
5+
<TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
66
<IsPackable>false</IsPackable>
77
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
8+
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\$(TargetFramework.ToLowerInvariant())\</IntermediateOutputPath>
89
</PropertyGroup>
910

1011
<PropertyGroup>

src/Java.Interop/Java.Interop.targets renamed to src/Java.Interop/Directory.Build.targets

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Runtime Condition="'$(OS)' != 'Windows_NT'">mono</Runtime>
5+
<_JNIEnvGenPath Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">$(BuildToolOutputFullPath)jnienv-gen.dll</_JNIEnvGenPath>
6+
<_JNIEnvGenPath Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(BuildToolOutputFullPath)jnienv-gen.exe</_JNIEnvGenPath>
7+
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' == 'True' ">dotnet "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
8+
<_RunJNIEnvGen Condition=" '$(JIBuildingForNetCoreApp)' != 'True' ">$(Runtime) "$(_JNIEnvGenPath)"</_RunJNIEnvGen>
59
</PropertyGroup>
610
<ItemGroup>
711
<CompileJavaInteropJar Include="java\com\xamarin\java_interop\internal\JavaProxyObject.java" />
@@ -16,14 +20,14 @@
1620
</ItemGroup>
1721
<Target Name="BuildJniEnvironment_g_cs"
1822
BeforeTargets="BeforeCompile"
19-
Inputs="$(JNIEnvGenPath)\jnienv-gen.exe"
23+
Inputs="$(_JNIEnvGenPath)"
2024
Outputs="Java.Interop\JniEnvironment.g.cs;$(IntermediateOutputPath)\jni.c">
2125
<MakeDir Directories="$(IntermediateOutputPath)" />
2226
<PropertyGroup>
2327
<_AddCompile Condition=" !Exists('Java.Interop\JniEnvironment.g.cs') ">True</_AddCompile>
2428
</PropertyGroup>
2529
<Exec
26-
Command="$(Runtime) &quot;$(JNIEnvGenPath)\jnienv-gen.exe&quot; Java.Interop\JniEnvironment.g.cs $(IntermediateOutputPath)\jni.c"
30+
Command="$(_RunJNIEnvGen) Java.Interop\JniEnvironment.g.cs $(IntermediateOutputPath)\jni.c"
2731
/>
2832
<ItemGroup>
2933
<Compile Include="Java.Interop\JniEnvironment.g.cs" Condition=" '$(_AddCompile)' == 'True' " />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<Private>False</Private>
7777
</Reference>
7878
</ItemGroup>
79-
<Import Project="Java.Interop.targets" />
79+
<Import Project="Directory.Build.targets" />
8080
<PropertyGroup>
8181
<BuildDependsOn>
8282
BuildJniEnvironment_g_cs;

src/Java.Interop/Java.Interop.csproj

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
55
<NoWarn>1591</NoWarn>
66
<SignAssembly>true</SignAssembly>
77
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
88
<DefineConstants>INTEROP;FEATURE_JNIENVIRONMENT_JI_PINVOKES;FEATURE_JNIOBJECTREFERENCE_INTPTRS;INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
99
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1010
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
1111
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
12-
</PropertyGroup>
13-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14-
<OutputPath>..\..\bin\Debug</OutputPath>
15-
<DocumentationFile>..\..\bin\Debug\Java.Interop.xml</DocumentationFile>
16-
<JNIEnvGenPath>..\..\bin\BuildDebug</JNIEnvGenPath>
17-
<DefineConstants>$(DefineConstants);DEBUG;NETSTANDARD;NETSTANDARD2_0</DefineConstants>
12+
<IntermediateOutputPath>$(BaseIntermediateOutputPath)$(Configuration)\$(TargetFramework.ToLowerInvariant())\</IntermediateOutputPath>
13+
<OutputPath>$(ToolOutputFullPath)</OutputPath>
14+
<DocumentationFile>$(ToolOutputFullPath)Java.Interop.xml</DocumentationFile>
15+
<JNIEnvGenPath>$(BuildToolOutputFullPath)</JNIEnvGenPath>
1816
<LangVersion>8.0</LangVersion>
1917
<Nullable>enable</Nullable>
2018
</PropertyGroup>
21-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
22-
<OutputPath>..\..\bin\Release</OutputPath>
23-
<DocumentationFile>..\..\bin\Release\Java.Interop.xml</DocumentationFile>
24-
<JNIEnvGenPath>..\..\bin\BuildRelease</JNIEnvGenPath>
25-
<LangVersion>8.0</LangVersion>
26-
<Nullable>enable</Nullable>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<DefineConstants>DEBUG;$(DefineConstants)</DefineConstants>
2721
</PropertyGroup>
2822
<ItemGroup>
2923
<Compile Remove="Java.Interop\JniLocationException.cs" />
3024
</ItemGroup>
31-
<Import Project="Java.Interop.targets" />
3225
<PropertyGroup>
3326
<BuildDependsOn>
3427
BuildJniEnvironment_g_cs;
@@ -60,7 +53,9 @@
6053
<PrivateAssets>all</PrivateAssets>
6154
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6255
</PackageReference>
63-
<ProjectReference Include="..\..\build-tools\jnienv-gen\jnienv-gen.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
56+
<ProjectReference Include="..\..\build-tools\jnienv-gen\jnienv-gen.csproj"
57+
ReferenceOutputAssembly="false"
58+
/>
6459
</ItemGroup>
6560
<ItemGroup>
6661
<Compile Condition=" '$(EnableDefaultCompileItems)' == 'true' " Update="Java.Interop\JavaPrimitiveArrays.cs">

0 commit comments

Comments
 (0)