Skip to content

Commit 0cd890b

Browse files
authored
[monodroid] Build the Xamarin.Android runtime for net6 (#5665)
Context: dotnet/runtime#48416 Context: dotnet/runtime#44505 Context: #5537 Update the `src/monodroid` build system to build the native Xamarin.Android runtime libraries (e.g. `libmono-android.debug.so`) against the MonoVM shipped from the `dotnet/runtime` repository in the `Microsoft.NETCore.App.Runtime.*` NuGet packages. These NuGet packages also contain the header files needed to access and use MonoVM's embedding API. We thus ~double the number of libraries built by `src/monodroid`, with one set of builds against the "legacy" Mono, using Mono from the SDK archives, and another set of builds against .NET 6 MonoVM. This change requires the introduction of new target directories in `$(XAInstallPrefix)xbuild/Xamarin/Android/lib` (e.g. `bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/lib`): * `arm64-v8a-net6` * `armeabi-v7a-net6` * `x86_64-net6` * `x86-net6` These directories now contain only the shared libraries together comprising the Xamarin.Android native runtime libraries: * `libmono-android.*.so` * `libxamarin-debug-app-helper*.so` * `libxamarin-app.so` Mono runtime libraries are *not* copied from their respective NuGet packages; the .NET 6 NuGet packages are required to obtain them. Compared to the "legacy" builds, we are missing the libMonoPosixHelper.so` library. This helper lib will eventually be placed in a `Mono.Posix` NuGet, once we are able to separate `Mono.Posix` files from the Mono sources and place them in a [separate repository][0]. `xaprepare` is modified to generate MSBuild and cmake fragments responsible for building net6 runtime binaries. The `libmono-android.*.so` native libraries no longer need to export any entry points for P/Invoke purposes. Instead, the new `PINVOKE_OVERRIDE` [runtime property][1] is used to hook into the P/Invoke lookup process. This allows us to not only hide the public symbols, but also to remove the `libxa-internal-api.so` library (d583b7c) completely. [0]: https://github.com/mono/mono.posix [1]: https://docs.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting#step-3---prepare-runtime-properties
1 parent a054e5f commit 0cd890b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2043
-249
lines changed

.external

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
xamarin/monodroid:main@2e93b630e47701dae56f426fe5934846d571832b
1+
xamarin/monodroid:main@dade1f497271f3ae5ceb1fe8c6c672b399a369ec
22
mono/mono:2020-02@c66141a8c7ba2566c578c2dd012b2b723e006213

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
url = https://github.com/Guardsquare/proguard.git
3636
branch = master
3737
ignore = dirty
38+
[submodule "external/robin-map"]
39+
path = external/robin-map
40+
url = https://github.com/Tessil/robin-map.git
41+
branch = master
3842
[submodule "external/sqlite"]
3943
path = external/sqlite
4044
url = https://github.com/xamarin/sqlite.git

Configuration.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@
7575
<DotNetPreviewPath Condition=" '$(DotNetPreviewPath)' == '' ">$(AndroidToolchainDirectory)\dotnet\</DotNetPreviewPath>
7676
<DotNetPreviewTool Condition=" '$(DotNetPreviewTool)' == '' ">$(DotNetPreviewPath)dotnet</DotNetPreviewTool>
7777
<!-- Version number from: https://github.com/dotnet/installer#installers-and-binaries -->
78+
<!-- Please update DotNetRuntimePacksVersion below accordingly -->
7879
<DotNetPreviewVersionBand Condition=" '$(DotNetPreviewVersionBand)' == '' ">6.0.100</DotNetPreviewVersionBand>
7980
<DotNetPreviewVersionFull Condition=" '$(DotNetPreviewVersionFull)' == '' ">$(DotNetPreviewVersionBand)-preview.1.21109.8</DotNetPreviewVersionFull>
81+
<!-- This version comes from the a file in the dotnet distribution: sdk/$(DotNetPreviewVersionFull)/dotnet.runtimeconfig.json (the `runtimeOptions/framework/version key`) -->
82+
<DotNetRuntimePacksVersion Condition=" '$(DotNetRuntimePacksVersion)' == '' ">6.0.0-preview.2.21108.2</DotNetRuntimePacksVersion>
8083
<ILLinkVersionBand Condition=" '$(ILLinkVersionBand)' == '' ">6.0.0</ILLinkVersionBand>
8184
<ILLinkVersionFull Condition=" '$(ILLinkVersionFull)' == '' ">$(ILLinkVersionBand)-alpha.1.21109.1</ILLinkVersionFull>
8285
<WixToolPath Condition=" '$(WixToolPath)' == '' ">$(AndroidToolchainDirectory)\wix\</WixToolPath>

ThirdPartyNotices.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The attached notices are provided for information only.
1515
2. bazelbuild/bazel (https://github.com/bazelbuild/bazel/)
1616
3. force-net/crc32.net (https://github.com/force-net/Crc32.NET)
1717
4. nunit/nunitlite (https://github.com/nunit/nunitlite/)
18+
5. tessil/robin-map (https://github.com/Tessil/robin-map)
1819

1920
%% android/platform/tools/base NOTICES AND INFORMATION BEGIN HERE
2021
=================================================================
@@ -487,3 +488,31 @@ THE SOFTWARE.
487488
=====================================================
488489
END OF nunit/nunitlite NOTICES AND INFORMATION
489490

491+
%% tessil/robin-map NOTICES AND INFORMATION BEGIN HERE
492+
======================================================
493+
MIT License
494+
495+
Copyright (c) 2017 Thibaut Goetghebuer-Planchon <tessil@gmx.com>
496+
497+
Permission is hereby granted, free of charge, to any person obtaining a copy
498+
of this software and associated documentation files (the "Software"), to deal
499+
in the Software without restriction, including without limitation the rights
500+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
501+
copies of the Software, and to permit persons to whom the Software is
502+
furnished to do so, subject to the following conditions:
503+
504+
The above copyright notice and this permission notice shall be included in all
505+
copies or substantial portions of the Software.
506+
507+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
508+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
509+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
510+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
511+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
512+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
513+
SOFTWARE.
514+
515+
516+
======================================================
517+
END OF tessil/robin-map NOTICES AND INFORMATION
518+

build-tools/create-packs/Directory.Build.targets

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@
7777
<Target Name="CreateAllPacks"
7878
DependsOnTargets="BuildILLinkCustomStep;DeleteExtractedWorkloadPacks;_SetGlobalProperties">
7979
<RemoveDir Directories="$(XamarinAndroidSourcePath)bin\Build$(Configuration)\nupkgs" />
80-
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') -p:AndroidRID=android-arm -p:AndroidABI=armeabi-v7a &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
81-
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') -p:AndroidRID=android-arm64 -p:AndroidABI=arm64-v8a &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
82-
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') -p:AndroidRID=android-x86 -p:AndroidABI=x86 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
83-
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') -p:AndroidRID=android-x64 -p:AndroidABI=x86_64 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
80+
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') -p:AndroidRID=android-arm -p:AndroidABI=armeabi-v7a-net6 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
81+
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') -p:AndroidRID=android-arm64 -p:AndroidABI=arm64-v8a-net6 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
82+
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') -p:AndroidRID=android-x86 -p:AndroidABI=x86-net6 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
83+
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') -p:AndroidRID=android-x64 -p:AndroidABI=x86_64-net6 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
8484
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Ref.proj&quot;" />
8585
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') -p:AndroidHostRID=linux-x64 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Sdk.proj&quot;" Condition=" '$(HostOS)' == 'Linux' " />
8686
<Exec Command="$(DotNetPreviewTool) pack @(_GlobalProperties, ' ') -p:AndroidHostRID=osx-x64 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Sdk.proj&quot;" Condition=" '$(HostOS)' == 'Darwin' " />

build-tools/create-packs/Microsoft.Android.Runtime.proj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ projects that use the Microsoft.Android framework in .NET 5.
1111

1212
<PropertyGroup>
1313
<AndroidRID Condition=" '$(AndroidRID)' == '' ">android-arm64</AndroidRID>
14-
<AndroidABI Condition=" '$(AndroidABI)' == '' ">arm64-v8a</AndroidABI>
14+
<AndroidABI Condition=" '$(AndroidABI)' == '' ">arm64-v8a-net6</AndroidABI>
1515
<PackageId>Microsoft.Android.Runtime.$(AndroidRID)</PackageId>
1616
<Description>Microsoft.Android runtime components. Please do not reference directly.</Description>
1717
<_AndroidRuntimePackAssemblyPath>runtimes\$(AndroidRID)\lib\net6.0</_AndroidRuntimePackAssemblyPath>
@@ -39,7 +39,6 @@ projects that use the Microsoft.Android framework in .NET 5.
3939
<_AndroidRuntimePackAssemblies Include="$(_MonoAndroidNETOutputDir)Mono.Android.Export.dll" />
4040
<_AndroidRuntimePackAssets Include="$(XAInstallPrefix)xbuild\Xamarin\Android\lib\$(AndroidABI)\libmono-android.debug.so" />
4141
<_AndroidRuntimePackAssets Include="$(XAInstallPrefix)xbuild\Xamarin\Android\lib\$(AndroidABI)\libmono-android.release.so" />
42-
<_AndroidRuntimePackAssets Include="$(XAInstallPrefix)xbuild\Xamarin\Android\lib\$(AndroidABI)\libxa-internal-api.so" />
4342
<_AndroidRuntimePackAssets Include="$(XAInstallPrefix)xbuild\Xamarin\Android\lib\$(AndroidABI)\libxamarin-debug-app-helper.so" />
4443
<FrameworkListFileClass Include="@(_AndroidRuntimePackAssemblies->'%(Filename)%(Extension)')" Profile="Android" />
4544
<FrameworkListFileClass Include="@(_AndroidRuntimePackAssets->'%(Filename)%(Extension)')" Profile="Android" />

build-tools/create-pkg/create-pkg.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<MSBuildFrameworksDir>$(XAFrameworkDir)\lib\xamarin.android\xbuild-frameworks\MonoAndroid</MSBuildFrameworksDir>
2828
</PropertyGroup>
2929
<RemoveDir Directories="$(PayloadDir)" />
30+
<ItemGroup>
31+
<!-- Remove items with '%(ExcludeFromLegacy)' == 'true' metadata -->
32+
<MSBuildItemsUnix Remove="@(MSBuildItemsUnix)" Condition=" '%(MSBuildItemsUnix.ExcludeFromLegacy)' == 'true' " />
33+
</ItemGroup>
3034
<Copy
3135
SourceFiles="@(FrameworkItemsUnix)"
3236
DestinationFiles="@(FrameworkItemsUnix->'$(MSBuildFrameworksDir)\%(RelativePath)')"

build-tools/create-vsix/create-vsix.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<ReferenceAssemblies Include="@(FrameworkItemsWin)" >
3333
<VSIXSubPath>Microsoft/Framework/MonoAndroid/$([System.IO.Path]::GetDirectoryName(%(RelativePath)))</VSIXSubPath>
3434
</ReferenceAssemblies>
35+
<!-- Remove items with '%(ExcludeFromLegacy)' == 'true' metadata -->
36+
<MSBuildItemsWin Remove="@(MSBuildItemsWin)" Condition=" '%(MSBuildItemsWin.ExcludeFromLegacy)' == 'true' " />
3537
<MSBuild Include="@(MSBuildItemsWin)" >
3638
<VSIXSubPath>Xamarin/Android/$([System.IO.Path]::GetDirectoryName(%(RelativePath)))</VSIXSubPath>
3739
</MSBuild>

build-tools/installers/create-installers.targets

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,14 @@
227227
<_MSBuildFiles Include="$(MSBuildSrcDir)\startup-xf.aotprofile" />
228228
<_MSBuildFiles Include="$(MSBuildSrcDir)\r8.jar" />
229229
<_MSBuildFiles Include="$(MSBuildSrcDir)\bundletool.jar" ExcludeFromAndroidNETSdk="true" />
230-
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime.jar" />
231-
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev.jar" />
232-
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime.dex" />
233-
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev.dex" />
230+
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime.jar" ExcludeFromAndroidNETSdk="true" />
231+
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev.jar" ExcludeFromAndroidNETSdk="true" />
232+
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime.dex" ExcludeFromAndroidNETSdk="true" />
233+
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev.dex" ExcludeFromAndroidNETSdk="true" />
234+
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_net6.jar" ExcludeFromLegacy="true" />
235+
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev_net6.jar" ExcludeFromLegacy="true" />
236+
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_net6.dex" ExcludeFromLegacy="true" />
237+
<_MSBuildFiles Include="$(MSBuildSrcDir)\java_runtime_fastdev_net6.dex" ExcludeFromLegacy="true" />
234238
<_MSBuildFiles Include="$(MSBuildSrcDir)\manifestmerger.jar" />
235239
<_MSBuildFiles Include="$(MSBuildSrcDir)\protobuf-net.dll" />
236240
<_MSBuildFiles Include="$(MSBuildSrcDir)\SgmlReaderDll.dll" />

build-tools/scripts/Ndk.projitems.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,42 @@
33
<PropertyGroup>
44
<AndroidNdkVersion Condition=" '$(AndroidNdkVersion)' == '' ">@NDK_RELEASE@</AndroidNdkVersion>
55
<AndroidNdkApiLevel_ArmV7a Condition=" '$(AndroidNdkApiLevel_ArmV7a)' == '' ">@NDK_ARMEABI_V7_API@</AndroidNdkApiLevel_ArmV7a>
6+
<AndroidNdkApiLevel_ArmV7a_NET6 Condition=" '$(AndroidNdkApiLevel_ArmV7a_NET6)' == '' ">@NDK_ARMEABI_V7_API_NET6@</AndroidNdkApiLevel_ArmV7a_NET6>
67
<AndroidNdkApiLevel_ArmV8a Condition=" '$(AndroidNdkApiLevel_ArmV8a)' == '' ">@NDK_ARM64_V8A_API@</AndroidNdkApiLevel_ArmV8a>
8+
<AndroidNdkApiLevel_ArmV8a_NET6 Condition=" '$(AndroidNdkApiLevel_ArmV8a_NET6)' == '' ">@NDK_ARM64_V8A_API_NET6@</AndroidNdkApiLevel_ArmV8a_NET6>
79
<AndroidNdkApiLevel_X86 Condition=" '$(AndroidNdkApiLevel_X86)' == '' ">@NDK_X86_API@</AndroidNdkApiLevel_X86>
10+
<AndroidNdkApiLevel_X86_NET6 Condition=" '$(AndroidNdkApiLevel_X86_NET6)' == '' ">@NDK_X86_API_NET6@</AndroidNdkApiLevel_X86_NET6>
811
<AndroidNdkApiLevel_X86_64 Condition=" '$(AndroidNdkApiLevel_X86_64)' == '' ">@NDK_X86_64_API@</AndroidNdkApiLevel_X86_64>
12+
<AndroidNdkApiLevel_X86_64_NET6 Condition=" '$(AndroidNdkApiLevel_X86_64_NET6)' == '' ">@NDK_X86_64_API_NET6@</AndroidNdkApiLevel_X86_64_NET6>
913
</PropertyGroup>
1014

1115
<ItemGroup>
1216
<AndroidSupportedTargetJitAbi
1317
Include="armeabi-v7a"
1418
Condition=" $(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':armeabi-v7a:')) ">
1519
<ApiLevel>$(AndroidNdkApiLevel_ArmV7a)</ApiLevel>
20+
<ApiLevelNET6>$(AndroidNdkApiLevel_ArmV7a_NET6)</ApiLevelNET6>
1621
</AndroidSupportedTargetJitAbi>
1722

1823
<AndroidSupportedTargetJitAbi
1924
Include="arm64-v8a"
2025
Condition=" $(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':arm64-v8a:')) ">
2126
<ApiLevel>$(AndroidNdkApiLevel_ArmV8a)</ApiLevel>
27+
<ApiLevelNET6>$(AndroidNdkApiLevel_ArmV8a_NET6)</ApiLevelNET6>
2228
</AndroidSupportedTargetJitAbi>
2329

2430
<AndroidSupportedTargetJitAbi
2531
Include="x86"
2632
Condition=" $(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':x86:')) ">
2733
<ApiLevel>$(AndroidNdkApiLevel_X86)</ApiLevel>
34+
<ApiLevelNET6>$(AndroidNdkApiLevel_X86_NET6)</ApiLevelNET6>
2835
</AndroidSupportedTargetJitAbi>
2936

3037
<AndroidSupportedTargetJitAbi
3138
Include="x86_64"
3239
Condition=" $(AndroidSupportedTargetJitAbisForConditionalChecks.Contains (':x86_64:')) ">
3340
<ApiLevel>$(AndroidNdkApiLevel_X86_64)</ApiLevel>
41+
<ApiLevelNET6>$(AndroidNdkApiLevel_X86_64_NET6)</ApiLevelNET6>
3442
</AndroidSupportedTargetJitAbi>
3543
</ItemGroup>
3644
</Project>

0 commit comments

Comments
 (0)