Skip to content

Commit e2854ee

Browse files
authored
[Mono.Android] Build latest stable version against netcoreapp3.1 (#4419)
We expect the .NET 5 BCL to closely resemble the .NET Core 3.1 BCL. Continue preparing for .NET 5 and build `Mono.Android.dll` against the `netcoreapp3.1` target framework, to ensure that the APIs that we need actually exist. Additionally, the `Mono.Android.csproj` build will effectively be a no-op when targeting `netcoreapp3.1` if `$(AndroidFrameworkVersion)` is not equal to `$(AndroidLatestStableFrameworkVersion)`, as we currently plan on only shipping *one* `Mono.Android.dll` assembly as part of .NET 5, so there is no need to build `Mono.Android.dll` against other `$(TargetFrameworkVersion)` values. When building for `netcoreapp3.1`, `Mono.Android.dll` uses the `Java.Interop.dll` which is built for .NET Standard, instead of the one built against the `MonoAndroid` framework. We may want to consider updating `Java.Interop.csproj` to multitarget against `netcoreapp3.1` as well.
1 parent 5563a79 commit e2854ee

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

build-tools/scripts/JavaCallableWrappers.targets

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
Inputs="$(JavaCallableWrapperAbsAssembly);@(JavaCallableWrapperSource)"
66
Outputs="$(OutputPath)mono.android.jar">
77
<MakeDir Directories="$(IntermediateOutputPath)jcw;$(IntermediateOutputPath)jcw\bin" />
8+
<ItemGroup>
9+
<_CorlibPath Include="@(ReferencePath->'%(RootDir)%(Directory)')" Condition=" '%(FileName)%(Extension)' == 'mscorlib.dll' " />
10+
</ItemGroup>
811
<PropertyGroup>
12+
<_CorlibDir>@(_CorlibPath)</_CorlibDir>
913
<OutputPathAbs Condition="$([System.IO.Path]::IsPathRooted($(OutputPath)))">$(OutputPath)</OutputPathAbs>
1014
<OutputPathAbs Condition=" '$(OutputPathAbs)' == '' ">$(MSBuildProjectDirectory)\$(OutputPath)</OutputPathAbs>
1115
<JcwGen>"$(XAInstallPrefix)xbuild\Xamarin\Android\jcw-gen.exe" -v10</JcwGen>
12-
<_LibDirs>-L "$(OutputPathAbs.TrimEnd('\'))" -L "$(OutputPathAbs)..\v1.0" -L "$(OutputPathAbs)..\v1.0\Facades"</_LibDirs>
16+
<_LibDirs>-L "$(OutputPathAbs.TrimEnd('\'))"</_LibDirs>
17+
<_LibDirs Condition=" '$(TargetFramework)' != 'netcoreapp3.1' ">$(_LibDirs) -L "$(OutputPathAbs)..\v1.0" -L "$(OutputPathAbs)..\v1.0\Facades"</_LibDirs>
18+
<_LibDirs Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">$(_LibDirs) -L "$(_CorlibDir.TrimEnd('\'))"</_LibDirs>
1319
<_Out>-o "$(MSBuildProjectDirectory)\$(IntermediateOutputPath)jcw\src"</_Out>
1420
</PropertyGroup>
1521
<Exec

src/Mono.Android/Android.Runtime/JNIEnv.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ internal static unsafe void Initialize (JnienvInitializeArgs* args)
170170
else
171171
IdentityHash = v => v;
172172

173+
#if MONOANDROID1_0
173174
Mono.SystemDependencyProvider.Initialize ();
175+
#endif
174176

175177
BoundExceptionType = (BoundExceptionType)args->ioExceptionType;
176178
androidRuntime = new AndroidRuntime (args->env, args->javaVm, androidSdkVersion > 10, args->grefLoader, args->Loader_loadClass, args->jniAddNativeMethodRegistrationAttributePresent != 0);

src/Mono.Android/Mono.Android.csproj

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project Sdk="Microsoft.NET.Sdk">
2+
<Project>
33

4+
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
45
<Import Project="..\..\Configuration.props" />
56

67
<PropertyGroup>
7-
<TargetFramework>monoandroid10</TargetFramework>
8+
<TargetFrameworks>monoandroid10;netcoreapp3.1</TargetFrameworks>
89
<RootNamespace>Android</RootNamespace>
910
<SignAssembly>true</SignAssembly>
1011
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
@@ -30,6 +31,11 @@
3031
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
3132
</PropertyGroup>
3233

34+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
35+
<OutputPath>$(XAInstallPrefix)xbuild-frameworks\Xamarin.Android.App\$(TargetFramework)\</OutputPath>
36+
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
37+
</PropertyGroup>
38+
3339
<ItemGroup Condition=" '$(TargetFramework)' == 'monoandroid10' ">
3440
<Reference Include="mscorlib">
3541
<HintPath>$(OutputPath)..\v1.0\mscorlib.dll</HintPath>
@@ -73,6 +79,10 @@
7379
</Reference>
7480
</ItemGroup>
7581

82+
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
83+
<ProjectReference Include="..\..\external\Java.Interop\src\Java.Interop\Java.Interop.csproj" />
84+
</ItemGroup>
85+
7686
<ItemGroup>
7787
<Compile Include="..\..\external\Java.Interop\src\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings\JavaNativeTypeManager.cs">
7888
<Link>JavaNativeTypeManager.cs</Link>
@@ -331,9 +341,16 @@
331341
<ProjectReference Include="..\..\build-tools\api-merge\api-merge.csproj" ReferenceOutputAssembly="false" />
332342
<ProjectReference Include="..\..\build-tools\api-xml-adjuster\api-xml-adjuster.csproj" ReferenceOutputAssembly="false" />
333343
<ProjectReference Include="..\..\build-tools\jnienv-gen\jnienv-gen.csproj" ReferenceOutputAssembly="false" />
334-
<ProjectReference Include="..\..\external\Java.Interop\tools\generator\generator.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
335-
<ProjectReference Include="..\..\external\Java.Interop\tools\jcw-gen\jcw-gen.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
344+
<!-- Explicitly pass the target framework of the project so we don't have conflicts with the multiple targets in this file. -->
345+
<ProjectReference Include="..\..\external\Java.Interop\tools\generator\generator.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=net472"/>
346+
<ProjectReference Include="..\..\external\Java.Interop\tools\jcw-gen\jcw-gen.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=net472" />
336347
<ProjectReference Include="..\..\src\java-runtime\java-runtime.csproj" ReferenceOutputAssembly="false" />
337348
</ItemGroup>
338349

350+
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
351+
<!-- Only build the 'netcoreapp3.1' version of 'Mono.Android.dll' once for the latest stable Android version. -->
352+
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' And '$(AndroidFrameworkVersion)' != '$(AndroidLatestStableFrameworkVersion)' ">
353+
<BuildDependsOn></BuildDependsOn>
354+
</PropertyGroup>
355+
339356
</Project>

src/Mono.Android/Mono.Android.targets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</ItemGroup>
1111
<Target Name="_BuildJavaInterop"
1212
BeforeTargets="BeforeResolveReferences"
13+
Condition=" '$(TargetFramework)' == 'monoandroid10' "
1314
Inputs="$(MSBuildThisFile);$(JavaInteropFullPath)\src\Java.Interop\Java.Interop.csproj"
1415
Outputs="$(OutputPath)\..\v1.0\Java.Interop.dll">
1516
<PropertyGroup>
@@ -134,6 +135,7 @@
134135
</ItemGroup>
135136
<Target Name="_GenerateFrameworkList"
136137
BeforeTargets="GetTargetFrameworkProperties;GetReferenceAssemblyPaths;ResolveReferences"
138+
Condition=" '$(TargetFramework)' == 'monoandroid10' "
137139
Inputs="$(MSBuildProjectFullPath)"
138140
Outputs="$(OutputPath)RedistList\FrameworkList.xml">
139141
<MakeDir Directories="$(OutputPath)RedistList" />
@@ -185,7 +187,7 @@
185187
<Target
186188
Name="_CheckApiCompatibility"
187189
Condition=" '$(DisableApiCompatibilityCheck)' != 'True' "
188-
AfterTargets="Build"
190+
AfterTargets="CopyFilesToOutputDirectory"
189191
Inputs="$(TargetPath);@(ApiCompatibilityFiles)"
190192
Outputs="$(IntermediateOutputPath)CheckApiCompatibility.stamp">
191193
<CheckApiCompatibility

0 commit comments

Comments
 (0)