Skip to content

Commit 0638c89

Browse files
[Microsoft.Android.Ref] use reference assembly for Mono.Android.dll
The `Microsoft.Android.Ref.nupkg` file is meant to only contain reference assemblies, and we are currently shipping the *real* assembly. The actual runtime assembly is found in the runtime pack for each RID: * `Microsoft.Android.Runtime.android.21-arm.nupkg` * `Microsoft.Android.Runtime.android.21-arm64.nupkg` * `Microsoft.Android.Runtime.android.21-x86.nupkg` * `Microsoft.Android.Runtime.android.21-x64.nupkg` To fix this, we need to set `$(ProduceReferenceAssembly)` for each assembly we distribute in `Microsoft.Android.Ref`. The MSBuild targets in dotnet/sdk already handle passing the correct reference assembly to the `<Csc/>` MSBuild task, and passing us the runtime assembly to place in `.apk` files. I also cleaned up `Mono.Android.Export.csproj` so we don't need to clear `$(BuildDependsOn)` after manually importing `Micrsoft.NET.Sdk`. We could simply change `$(TargetFrameworks)` instead. Using a reference assembly has the benefit of saving ~3.5 MB of file size: Length Name ------ ---- 7167945 Microsoft.Android.Ref.11.0.100-ci.master.120.nupkg 3641811 Microsoft.Android.Ref.11.0.100-ci.microsoft-android-ref.121.nupkg And saves ~18.9 MB when extracted: Size Compressed Name ------------ ------------ ------------------------ 32411136 6748183 ref\net5.0\Mono.Android.dll 78336 30619 ref\net5.0\Mono.Android.Export.dll 13564928 3244535 ref\net5.0\Mono.Android.dll 22016 8077 ref\net5.0\Mono.Android.Export.dll We will need a future change in xamarin/java.interop to make a reference assembly for `Java.Interop.dll`.
1 parent 28add0d commit 0638c89

4 files changed

Lines changed: 11 additions & 13 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Build.Tasks.SharedFramework.Sdk" />
1111
<UsingTask TaskName="CreateFrameworkListFile" AssemblyFile="$(DotNetBuildTasksSharedFrameworkTaskFile)"/>
1212

13-
<!-- Include initial pack content in ref and runtime. We aren't yet generating separate reference and runtime assemblies. -->
1413
<ItemGroup>
14+
<!-- NOTE: we don't have a reference assembly for Java.Interop.dll yet -->
15+
<_AndroidAppRefAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\Java.Interop.dll" />
16+
<_AndroidAppRefAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\ref\Mono.Android.dll" />
17+
<_AndroidAppRefAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\ref\Mono.Android.Export.dll" />
1518
<_AndroidAppPackAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\Java.Interop.dll" />
1619
<_AndroidAppPackAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\Mono.Android.dll" />
1720
<_AndroidAppPackAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\Mono.Android.Export.dll" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ by projects that use the Microsoft.Android framework in .NET 5.
3333
</PropertyGroup>
3434

3535
<ItemGroup>
36-
<_PackageFiles Include="@(_AndroidAppPackAssemblies)" PackagePath="$(_AndroidRefPackAssemblyPath)" TargetPath="$(_AndroidRefPackAssemblyPath)" />
36+
<_PackageFiles Include="@(_AndroidAppRefAssemblies)" PackagePath="$(_AndroidRefPackAssemblyPath)" TargetPath="$(_AndroidRefPackAssemblyPath)" />
3737
<_PackageFiles Include="$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android\netcoreapp3.1\mono.android.jar" PackagePath="$(_AndroidRefPackAssemblyPath)" />
3838
<_PackageFiles Include="$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android\netcoreapp3.1\mono.android.dex" PackagePath="$(_AndroidRefPackAssemblyPath)" />
3939
<_PackageFiles Include="$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android\netcoreapp3.1\AndroidApiInfo.xml" PackagePath="$(_AndroidRefPackAssemblyPath)" />

src/Mono.Android.Export/Mono.Android.Export.csproj

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

4-
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
53
<Import Project="..\..\Configuration.props" />
64

75
<PropertyGroup>
8-
<TargetFrameworks>monoandroid10;netcoreapp3.1</TargetFrameworks>
6+
<!-- Only build for netcoreapp3.1 for $(AndroidLatestStableFrameworkVersion) -->
7+
<TargetFrameworks Condition=" '$(AndroidFrameworkVersion)' != '$(AndroidLatestStableFrameworkVersion)' ">monoandroid10</TargetFrameworks>
8+
<TargetFrameworks Condition=" '$(AndroidFrameworkVersion)' == '$(AndroidLatestStableFrameworkVersion)' ">monoandroid10;netcoreapp3.1</TargetFrameworks>
99
<SignAssembly>true</SignAssembly>
1010
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
1111
<NoStdLib>true</NoStdLib>
1212
<ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
13+
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
1314
</PropertyGroup>
1415

1516
<PropertyGroup Condition=" '$(TargetFramework)' == 'monoandroid10' ">
@@ -59,11 +60,4 @@
5960
<ProjectReference Include="..\Mono.Android\Mono.Android.csproj" />
6061
</ItemGroup>
6162

62-
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
63-
64-
<!-- Only build the 'netcoreapp3.1' version of 'Mono.Android.Export.dll' once. -->
65-
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' And '$(AndroidFrameworkVersion)' != '$(AndroidLatestStableFrameworkVersion)' ">
66-
<BuildDependsOn></BuildDependsOn>
67-
</PropertyGroup>
68-
6963
</Project>

src/Mono.Android/Mono.Android.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
2222
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
2323
<Nullable>enable</Nullable>
24+
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
2425
</PropertyGroup>
2526

2627
<PropertyGroup Condition=" '$(TargetFramework)' == 'monoandroid10' ">

0 commit comments

Comments
 (0)