-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[One .NET] support building net6.0-android apps in .NET 7 (#6988)
We currently have a hard dependency between: * `Xamarin.Android.Build.Tasks.dll` * `libmonodroid.so` The design for building a `net6.0-android` app with a .NET 7 SDK results in us using a .NET 7 `Xamarin.Android.Builds.Tasks.dll` and a .NET 6 `libmonodroid.so`. This crashes with: E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "java_name_width" referenced by "/data/app/~~8CHtXY8wK4g7s9VcOLTQEg==/com.microsoft.net6.helloandroid-cUUhwuQls7TRb6JdBsbPdg==/split_config.arm64_v8a.apk!/lib/arm64-v8a/libmonodroid.so"... To solve this problem: * Define `$(AndroidNet6Version)` to specify our .NET 6 GA `32.0.301` build that is released. * Add an alias for a `Microsoft.Android.Sdk.$(HostOS).NET6` workload pack that loads a .NET 6 version of `Microsoft.Android.Sdk.$(HostOS)`. * Include both the .NET 6 and .NET 7 versions of these packs in the workload. * Check `$(TargetFrameworkVersion)` and import the .NET 7 or .NET 6 MSBuild targets when appropriate. * Update `@(KnownFrameworkReference)` to the version of .NET 6 that our .NET 7 packs know about. * We have a matching .NET 6 `Xamarin.Android.Build.Tasks.dll` and `libmonodroid.so`! This obviously increases our install footprint of `Microsoft.Android.Sdk.$(HostOS)` by 2x. We might be able to address this by splitting out some files into a `Microsoft.Android.Sdk.Tooling` pack that can be shared between .NET 6 and .NET 7. (Perhaps files like `bundletool.jar` and `r8.jar` could be shared?) One hack I had to put in place was to avoid the crash: E AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "mono_opt_aot_lazy_assembly_load" referenced by "/data/app/~~Fp4gEr_9sxU1qU6PoI-v6Q==/com.companyname.foo-EKEtL67XJI-d0H17_3oz3g==/lib/arm64/libmonodroid.so"... The .NET 7 SDK we are on does not yet know about .NET runtime 6.0.5 (it uses 6.0.3), so I manually fixed this version number for now. We should be able to remove this eventually when the .NET 7 SDK provides 6.0.5 by default. A second hack I put in place: Make `Microsoft.Android.Sdk.NET6` a "framework" and not an "sdk" within `WorkloadManifest.json`. This prevents *both* the .NET 6 `AutoImport.props` *and* .NET 7 `AutoImport.props` files from being imported, causing duplication of item groups/etc. This seems very weird, but this still works: <Import Project="Sdk.targets" Sdk="Microsoft.Android.Sdk" /> We can remove this if I condition everything in `AutoImport.props` behind a current `$(TargetFrameworkVersion)`. We would then need to ship this in a .NET 6 release.
- Loading branch information
1 parent
90aec41
commit fd47b02
Showing
10 changed files
with
85 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
26 changes: 26 additions & 0 deletions
26
src/Xamarin.Android.Build.Tasks/Microsoft.NET.Sdk.Android/WorkloadManifest.in.targets
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project> | ||
<ImportGroup Condition=" '$(TargetPlatformIdentifier)' == 'android' "> | ||
<Import Project="Sdk.targets" Sdk="Microsoft.Android.Sdk" | ||
Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '7.0')) " /> | ||
<Import Project="Sdk.targets" Sdk="Microsoft.Android.Sdk.NET6" | ||
Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0')) " /> | ||
</ImportGroup> | ||
|
||
<ItemGroup Condition=" '$(TargetPlatformIdentifier)' == 'android' and $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0')) "> | ||
<KnownFrameworkReference | ||
Update="Microsoft.Android" | ||
LatestRuntimeFrameworkVersion="@NET6_VERSION@" | ||
TargetingPackVersion="@NET6_VERSION@" | ||
/> | ||
<!-- | ||
HACK: | ||
The .NET 7 SDK specifies 6.0.3 for .NET 6, but our .NET 6 libmonodroid.so depends on 6.0.5. | ||
We should be able to remove this when we get a newer .NET 7 SDK. | ||
--> | ||
<KnownRuntimePack Update="Microsoft.NETCore.App" LatestRuntimeFrameworkVersion="6.0.5" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')) "> | ||
<SdkSupportedTargetPlatformIdentifier Include="android" DisplayName="Android" /> | ||
</ItemGroup> | ||
</Project> |
8 changes: 0 additions & 8 deletions
8
src/Xamarin.Android.Build.Tasks/Microsoft.NET.Sdk.Android/WorkloadManifest.targets
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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