From 0638c897d42d9a3f2a5129ed58fda21b608e9d52 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Tue, 15 Sep 2020 09:53:04 -0500 Subject: [PATCH] [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 `` 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`. --- build-tools/create-packs/Directory.Build.targets | 5 ++++- .../create-packs/Microsoft.Android.Ref.proj | 2 +- .../Mono.Android.Export.csproj | 16 +++++----------- src/Mono.Android/Mono.Android.csproj | 1 + 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/build-tools/create-packs/Directory.Build.targets b/build-tools/create-packs/Directory.Build.targets index 29e500a19e7..da9048761a1 100644 --- a/build-tools/create-packs/Directory.Build.targets +++ b/build-tools/create-packs/Directory.Build.targets @@ -10,8 +10,11 @@ - + + <_AndroidAppRefAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\Java.Interop.dll" /> + <_AndroidAppRefAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\ref\Mono.Android.dll" /> + <_AndroidAppRefAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\ref\Mono.Android.Export.dll" /> <_AndroidAppPackAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\Java.Interop.dll" /> <_AndroidAppPackAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\Mono.Android.dll" /> <_AndroidAppPackAssemblies Include="$(XamarinAndroidSourcePath)bin\$(Configuration)\lib\xamarin.android\xbuild-frameworks\Microsoft.Android\netcoreapp3.1\Mono.Android.Export.dll" /> diff --git a/build-tools/create-packs/Microsoft.Android.Ref.proj b/build-tools/create-packs/Microsoft.Android.Ref.proj index b3243bccc8d..0524ee3a068 100644 --- a/build-tools/create-packs/Microsoft.Android.Ref.proj +++ b/build-tools/create-packs/Microsoft.Android.Ref.proj @@ -33,7 +33,7 @@ by projects that use the Microsoft.Android framework in .NET 5. - <_PackageFiles Include="@(_AndroidAppPackAssemblies)" PackagePath="$(_AndroidRefPackAssemblyPath)" TargetPath="$(_AndroidRefPackAssemblyPath)" /> + <_PackageFiles Include="@(_AndroidAppRefAssemblies)" PackagePath="$(_AndroidRefPackAssemblyPath)" TargetPath="$(_AndroidRefPackAssemblyPath)" /> <_PackageFiles Include="$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android\netcoreapp3.1\mono.android.jar" PackagePath="$(_AndroidRefPackAssemblyPath)" /> <_PackageFiles Include="$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android\netcoreapp3.1\mono.android.dex" PackagePath="$(_AndroidRefPackAssemblyPath)" /> <_PackageFiles Include="$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android\netcoreapp3.1\AndroidApiInfo.xml" PackagePath="$(_AndroidRefPackAssemblyPath)" /> diff --git a/src/Mono.Android.Export/Mono.Android.Export.csproj b/src/Mono.Android.Export/Mono.Android.Export.csproj index 424ac71723b..714cb8dbe4a 100644 --- a/src/Mono.Android.Export/Mono.Android.Export.csproj +++ b/src/Mono.Android.Export/Mono.Android.Export.csproj @@ -1,15 +1,16 @@ - - + - - monoandroid10;netcoreapp3.1 + + monoandroid10 + monoandroid10;netcoreapp3.1 true ..\..\product.snk true false + true @@ -59,11 +60,4 @@ - - - - - - - diff --git a/src/Mono.Android/Mono.Android.csproj b/src/Mono.Android/Mono.Android.csproj index 1c9119295c8..aca1d1bd152 100644 --- a/src/Mono.Android/Mono.Android.csproj +++ b/src/Mono.Android/Mono.Android.csproj @@ -21,6 +21,7 @@ false false enable + true