Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/R8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class R8 : D8
public string? ProguardGeneratedApplicationConfiguration { get; set; }
public string? ProguardCommonXamarinConfiguration { get; set; }
public string? ProguardMappingFileOutput { get; set; }
public string? BuildMetadataFileOutput { get; set; }
public string []? ProguardConfigurationFiles { get; set; }

protected override string MainClass => "com.android.tools.r8.R8";
Expand Down Expand Up @@ -63,6 +64,11 @@ protected override string CreateResponseFile ()
// Now append R8-specific arguments to the response file
using var response = new StreamWriter (responseFile, append: true, encoding: Files.UTF8withoutBOM);

if (!BuildMetadataFileOutput.IsNullOrEmpty ()) {
WriteArg (response, "--build-metadata-output");
WriteArg (response, Path.GetFullPath (BuildMetadataFileOutput));
}

if (EnableMultiDex) {
if (MinSdkVersion >= 21) {
if (CustomMainDexListFiles?.Length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,31 @@ namespace Xamarin.Android.Build.Tests
public class PackagingTest : BaseTest
{
[Test]
public void CheckProguardMappingFileExists ()
public void CheckR8MetadataFilesExist ()
{
var proj = new XamarinAndroidApplicationProject {
IsRelease = true,
};
proj.SetProperty (proj.ReleaseProperties, KnownProperties.AndroidLinkTool, "r8");
// Projects must set $(AndroidCreateProguardMappingFile) to true to opt in
proj.SetProperty (proj.ReleaseProperties, "AndroidCreateProguardMappingFile", true);
proj.SetProperty ("AndroidPackageFormat", "aab");

using (var b = CreateApkBuilder ()) {
string mappingFile = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, "mapping.txt");
Assert.IsTrue (b.Build (proj), "build should have succeeded.");
FileAssert.Exists (mappingFile, $"'{mappingFile}' should have been generated.");
var aab = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, $"{proj.PackageName}-Signed.aab");
FileAssert.Exists (aab, $"'{aab}' should have been generated.");
using (var zip = ZipHelper.OpenZip (aab)) {
Assert.IsTrue (zip.Any (e => e.FullName == "BUNDLE-METADATA/com.android.tools.build.obfuscation/proguard.map"), $"AAB file `{aab}` should contain the ProGuard mapping.");
Assert.IsTrue (zip.Any (e => e.FullName == "BUNDLE-METADATA/com.android.tools/r8.json"), $"AAB file `{aab}` should contain the R8 build metadata.");
}

Assert.IsTrue (b.Build (proj), "second build should have succeeded.");
foreach (var target in new [] { "_CompileToDalvik", "_BuildApkEmbed" }) {
Assert.IsTrue (b.Output.IsTargetSkipped (target), $"`{target}` should be skipped!");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
<_AndroidLibraryFlatArchivesDirectory>$(IntermediateOutputPath)flata\</_AndroidLibraryFlatArchivesDirectory>
<_AndroidLibraryFlatFilesDirectory>$(IntermediateOutputPath)flat\</_AndroidLibraryFlatFilesDirectory>
<_AndroidStampDirectory>$(IntermediateOutputPath)stamp\</_AndroidStampDirectory>
<_AndroidR8BuildMetadataFile>$(IntermediateOutputPath)r8.json</_AndroidR8BuildMetadataFile>
<_AndroidApplicationSharedLibraryPath>$(IntermediateOutputPath)app_shared_libraries\</_AndroidApplicationSharedLibraryPath>
<_ResolvedUserAssembliesHashFile>$(IntermediateOutputPath)resolvedassemblies.hash</_ResolvedUserAssembliesHashFile>
<_AndroidResolvedResourcesHashFile>$(IntermediateOutputPath)_AndroidResolvedResources.hash</_AndroidResolvedResourcesHashFile>
Expand Down Expand Up @@ -2270,6 +2271,10 @@ because xbuild doesn't support framework reference assemblies.
Condition=" Exists('$(AndroidProguardMappingFile)') "
Include="com.android.tools.build.obfuscation/proguard.map:$(AndroidProguardMappingFile)"
/>
<AndroidAppBundleMetaDataFile
Condition=" (('$(AndroidLinkTool)' == 'r8' And '$(_ProguardProjectConfiguration)' != '') Or '$(AndroidEnableMultiDex)' == 'True') And Exists('$(_AndroidR8BuildMetadataFile)') "
Include="com.android.tools/r8.json:$(_AndroidR8BuildMetadataFile)"
/>
</ItemGroup>
</Target>

Expand Down
2 changes: 2 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.D8.targets
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Copyright (C) 2018 Xamarin. All rights reserved.
ProguardGeneratedReferenceConfiguration="$(_ProguardProjectConfiguration)"
ProguardGeneratedApplicationConfiguration="$(IntermediateOutputPath)proguard\proguard_project_primary.cfg"
ProguardMappingFileOutput="$(AndroidProguardMappingFile)"
BuildMetadataFileOutput="$(_AndroidR8BuildMetadataFile)"
ProguardConfigurationFiles="@(_ProguardConfiguration)"
EnableShrinking="$(_R8EnableShrinking)"
EnableMultiDex="$(AndroidEnableMultiDex)"
Expand Down Expand Up @@ -109,6 +110,7 @@ Copyright (C) 2018 Xamarin. All rights reserved.
<ItemGroup>
<FileWrites Include="$(_AndroidIntermediateDexOutputDirectory)*.dex" />
<FileWrites Include="$(AndroidProguardMappingFile)" />
<FileWrites Include="$(_AndroidR8BuildMetadataFile)" Condition=" Exists('$(_AndroidR8BuildMetadataFile)') " />
</ItemGroup>

</Target>
Expand Down