Skip to content

Commit d72156c

Browse files
jonathanpeppersjonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] Fix <Proguard /> w/ acw-map.txt (#1402)
Fixes: #1373 Since e5b1c92, the contents of the `acw-map.txt` file have changed. We have removed the fully qualified type names from the file, and there is some code in the `<Proguard />` task that relies on a specific number of lines per C# type. We need to update the for-loop to skip every third line instead of every fourth line. I also updated the loop to only index against the `acwLines` array once per loop interation, as a small performance improvement. The code is also a little more readable from this change. Lastly, I added some code to the proguard test so that it validates the proguard configuration file contains the appropriate contents. Prior to this, the test was only making sure the build succeeded.
1 parent 43d6f01 commit d72156c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/Proguard.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,10 @@ protected override string GenerateCommandLineCommands ()
130130
var classesZip = Path.Combine (ClassesOutputDirectory, "..", "classes.zip");
131131
var acwLines = File.ReadAllLines (AcwMapFile);
132132
using (var appcfg = File.CreateText (ProguardGeneratedApplicationConfiguration))
133-
for (int i = 0; i + 3 < acwLines.Length; i += 4)
133+
for (int i = 0; i + 2 < acwLines.Length; i += 3)
134134
try {
135-
var java = acwLines [i + 3].Substring (acwLines [i + 3].IndexOf (';') + 1);
135+
var line = acwLines [i + 2];
136+
var java = line.Substring (line.IndexOf (';') + 1);
136137
appcfg.WriteLine ("-keep class " + java + " { *; }");
137138
} catch {
138139
// skip invalid lines

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,12 @@ public void BuildProguardEnabledProject (bool isRelease, bool enableProguard, bo
450450
var proj = new XamarinAndroidApplicationProject () { IsRelease = isRelease, EnableProguard = enableProguard, UseLatestPlatformSdk = useLatestSdk, TargetFrameworkVersion = useLatestSdk ? "v7.1" : "v5.0" };
451451
using (var b = CreateApkBuilder (Path.Combine ("temp", $"BuildProguard Enabled Project(1){isRelease}{enableProguard}{useLatestSdk}"))) {
452452
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
453+
454+
if (isRelease && enableProguard) {
455+
var proguardProjectPrimary = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "proguard", "proguard_project_primary.cfg");
456+
FileAssert.Exists (proguardProjectPrimary);
457+
StringAssertEx.ContainsText (File.ReadAllLines (proguardProjectPrimary), "-keep class md52d9cf6333b8e95e8683a477bc589eda5.MainActivity");
458+
}
453459
}
454460
}
455461

0 commit comments

Comments
 (0)