diff --git a/Documentation/guides/building-apps/build-items.md b/Documentation/guides/building-apps/build-items.md index f8eb86092cc..3905cd51c7f 100644 --- a/Documentation/guides/building-apps/build-items.md +++ b/Documentation/guides/building-apps/build-items.md @@ -38,6 +38,26 @@ Used to provide an AOT profile, for use with profile-guided AOT. It can be also used from Visual Studio by setting the `AndroidAotProfile` build action to a file containing an AOT profile. +## AndroidAppBundleMetaDataFile + +Specifies a file that will be included as metadata in the Android App Bundle. +The format of the flag value is `:` where +`bundle-path` denotes the file location inside the App Bundle's metadata +directory, and `physical-file` is an existing file containing the raw data +to be stored. + +```xml + + + +``` + +See [bundletool](https://developer.android.com/studio/build/building-cmdline#build_your_app_bundle_using_bundletool) documentation for more details. + +Added in Xamarin.Android 12.3. + ## AndroidBoundLayout Indicates that the layout file is to have code-behind generated for it in case when diff --git a/Documentation/guides/building-apps/build-properties.md b/Documentation/guides/building-apps/build-properties.md index 366aebb2395..2198e02a52f 100644 --- a/Documentation/guides/building-apps/build-properties.md +++ b/Documentation/guides/building-apps/build-properties.md @@ -300,6 +300,28 @@ should be created instead of having support for all ABIs in a single `.apk`. See also the [Building ABI-Specific APKs](~/android/deploy-test/building-apps/abi-specific-apks.md) guide. +## AndroidCreateProguardMappingFile + +A boolean property that controls if a proguard mapping file is +generated as part of the build process. + +Adding the following to your csproj will cause the file to be +generated. This uses the [`AndroidProguardMappingFile`](#androidproguardmappingfile) property +to control the location of the final mapping file. + +``` +True +``` + +Note that if you are using `.aab` files the mapping file with be +automatically included in your package. So there is no need to upload +it to the Google Play Store manually. If you are using `.apk` files +you will need to manually upload the [`AndroidProguardMappingFile`](#androidproguardmappingfile). + +The default value is `False`. + +Added in Xamarin.Android 12.3. + ## AndroidDebugKeyAlgorithm Specifies the default @@ -987,7 +1009,19 @@ mean the `mapping.txt` file will be produced in the `$(OutputPath)` folder. This file can then be used when uploading packages to the Google Play Store. -The default value is `$(OutputPath)mapping.txt`. +By default this file is not produced. + +If you do want to generate this mapping file you can use the +[`AndroidCreateProguardMappingFile`](#androidcreateproguardmappingfile) property to create it . +Add the following in your project + +``` +True +``` + +or use `-p:AndroidCreateProguardMappingFile=True` on the command line. + +This will then generate the following file `$(OutputPath)mapping.txt`. This property was added in Xamarin.Android 11.2. diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs index 11f760263b4..213e09272d2 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildAppBundle.cs @@ -12,7 +12,7 @@ namespace Xamarin.Android.Tasks { /// /// Invokes `bundletool` to create an Android App Bundle (.aab file) - /// + /// /// Usage: bundletool build-bundle --modules=base.zip --output=foo.aab --config=BundleConfig.json /// public class BuildAppBundle : BundleTool @@ -63,9 +63,11 @@ public class BuildAppBundle : BundleTool public string BaseZip { get; set; } public string CustomBuildConfigFile { get; set; } - + public string [] Modules { get; set; } + public ITaskItem [] MetaDataFiles { get; set; } + [Required] public string Output { get; set; } @@ -130,6 +132,9 @@ internal override CommandLineBuilder GetCommandLineBuilder () cmd.AppendSwitchIfNotNull ("--modules ", string.Join (",", modules)); cmd.AppendSwitchIfNotNull ("--output ", Output); cmd.AppendSwitchIfNotNull ("--config ", temp); + foreach (var file in MetaDataFiles ?? Array.Empty ()) { + cmd.AppendSwitch ($"--metadata-file={file.ItemSpec}"); + } return cmd; } } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs index 8dd86522e3c..f434d6309e6 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs @@ -125,7 +125,7 @@ protected override string GenerateCommandLineCommands () if (!string.IsNullOrEmpty (ProguardMappingFileOutput)) { xamcfg.WriteLine ("-keepattributes SourceFile"); xamcfg.WriteLine ("-keepattributes LineNumberTable"); - xamcfg.WriteLine ($"-printmapping {Path.GetFullPath (ProguardMappingFileOutput)}"); + xamcfg.WriteLine ($"-printmapping \"{Path.GetFullPath (ProguardMappingFileOutput)}\""); } } } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs b/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs index 9621ecce762..81d65a2c218 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/R8.cs @@ -104,7 +104,7 @@ protected override CommandLineBuilder GetCommandLineBuilder () if (!string.IsNullOrEmpty (ProguardMappingFileOutput)) { xamcfg.WriteLine ("-keepattributes SourceFile"); xamcfg.WriteLine ("-keepattributes LineNumberTable"); - xamcfg.WriteLine ($"-printmapping {Path.GetFullPath (ProguardMappingFileOutput)}"); + xamcfg.WriteLine ($"-printmapping \"{Path.GetFullPath (ProguardMappingFileOutput)}\""); } } } @@ -125,7 +125,7 @@ protected override CommandLineBuilder GetCommandLineBuilder () if (!string.IsNullOrEmpty (ProguardMappingFileOutput)) { lines.Add ("-keepattributes SourceFile"); lines.Add ("-keepattributes LineNumberTable"); - lines.Add ($"-printmapping {Path.GetFullPath (ProguardMappingFileOutput)}"); + lines.Add ($"-printmapping \"{Path.GetFullPath (ProguardMappingFileOutput)}\""); } File.WriteAllLines (temp, lines); tempFiles.Add (temp); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs index 7e096ecfb39..fc45875c5ac 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs @@ -56,8 +56,8 @@ public void CheckProguardMappingFileExists () }; proj.SetProperty (proj.ReleaseProperties, KnownProperties.AndroidDexTool, "d8"); proj.SetProperty (proj.ReleaseProperties, KnownProperties.AndroidLinkTool, "r8"); - // Projects must provide a $(AndroidProguardMappingFile) value to opt in - proj.SetProperty (proj.ReleaseProperties, "AndroidProguardMappingFile", @"$(OutputPath)\mapping.txt"); + // Projects must set $(AndroidCreateProguardMappingFile) to true to opt in + proj.SetProperty (proj.ReleaseProperties, "AndroidCreateProguardMappingFile", true); using (var b = CreateApkBuilder ()) { string mappingFile = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, "mapping.txt"); diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 92d9efa5aeb..63d50156df6 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -1807,6 +1807,7 @@ because xbuild doesn't support framework reference assemblies. _CreateApplicationSharedLibraries; _GetMonoPlatformJarPath; _GetLibraryImports; + _SetProguardMappingFileProperty; _CalculateProguardConfigurationFiles; <_CompileToDalvikInputs> @@ -1826,6 +1827,12 @@ because xbuild doesn't support framework reference assemblies. + + + $(OutputPath)mapping.txt + + + @@ -1967,6 +1974,12 @@ because xbuild doesn't support framework reference assemblies. $(ApkFileIntermediate) + + + @@ -2064,6 +2077,7 @@ because xbuild doesn't support framework reference assemblies. Output="$(_AppBundleIntermediate)" UncompressedFileExtensions="$(AndroidStoreUncompressedFileExtensions)" CustomBuildConfigFile="$(AndroidBundleConfigurationFile)" + MetaDataFiles="@(AndroidAppBundleMetaDataFile)" /> diff --git a/tests/apk-sizes-reference/com.companyname.vsandroidapp-Signed-Release.apkdesc b/tests/apk-sizes-reference/com.companyname.vsandroidapp-Signed-Release.apkdesc index 2dafe6e3ccd..a9512fdd8a1 100644 --- a/tests/apk-sizes-reference/com.companyname.vsandroidapp-Signed-Release.apkdesc +++ b/tests/apk-sizes-reference/com.companyname.vsandroidapp-Signed-Release.apkdesc @@ -5,13 +5,13 @@ "Size": 2896 }, "assemblies/assemblies.blob": { - "Size": 2026794 + "Size": 2027538 }, "assemblies/assemblies.manifest": { "Size": 1574 }, "classes.dex": { - "Size": 2940564 + "Size": 2940568 }, "lib/armeabi-v7a/libmono-btls-shared.so": { "Size": 1112688 @@ -20,16 +20,16 @@ "Size": 736396 }, "lib/armeabi-v7a/libmonodroid.so": { - "Size": 232320 + "Size": 234328 }, "lib/armeabi-v7a/libmonosgen-2.0.so": { - "Size": 4456332 + "Size": 4456576 }, "lib/armeabi-v7a/libxa-internal-api.so": { "Size": 48844 }, "lib/armeabi-v7a/libxamarin-app.so": { - "Size": 46832 + "Size": 46844 }, "lib/x86/libmono-btls-shared.so": { "Size": 1459584 @@ -38,16 +38,16 @@ "Size": 803352 }, "lib/x86/libmonodroid.so": { - "Size": 303316 + "Size": 305648 }, "lib/x86/libmonosgen-2.0.so": { - "Size": 4212220 + "Size": 4212336 }, "lib/x86/libxa-internal-api.so": { "Size": 61112 }, "lib/x86/libxamarin-app.so": { - "Size": 45500 + "Size": 45632 }, "META-INF/android.arch.core_runtime.version": { "Size": 6 @@ -1610,5 +1610,5 @@ "Size": 320016 } }, - "PackageSize": 9500681 + "PackageSize": 9504777 } \ No newline at end of file