Skip to content

Commit

Permalink
[tests] cleanup and fix failing MSBuild tests (#4641)
Browse files Browse the repository at this point in the history
Since a648981, we have a few MSBuild tests failing related to
multi-dex, because a648981 bumps our minimum Android API level to
API-21, which is *also* the minimum that `d8` requires in order to
automatically use multi-dex.

`BuildApplicationRequiresMultiDex("d8")`: for now I've just ignored
this test when running with `$(AndroidDexTool)`=d8.  When API-21 is
the minimum, `d8` is able to setup multi-dex automatically and  the
build won't fail.  I will need to revisit this in the future to
decide what Xamarin.Android should do about multi-dex going forward.

`BuildHasNoWarnings(False,True,True,"apk")`: one case we were
asserting there was 1 warning.  Now there are 0 warnings.

`BuildMultiDexApplication(False,"v7.1")`: this test needed to be
parameterized for `AndroidDexTool` of `dx` and `d8`.  I also generally
cleaned it up, removing `useJackAndJill` and simplifying assertions.
  • Loading branch information
jonathanpeppers authored Apr 30, 2020
1 parent 24227f8 commit 64d0c0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ public partial class BuildTest : BaseTest
/* expectedResult */ true,
},
};
// useJackAndJill, useLatestSdk
static object [] JackFlagAndFxVersion () => new object [] {
new Object [] { false, "v7.1" },
// Disabled because Jack DOESN'T work
// re-enable once it does.
//new Object [] { true, false },
//new Object [] { true, true },
};

static object [] RuntimeChecks () => new object [] {
new object[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,7 @@ public void BuildHasNoWarnings (bool isRelease, bool xamarinForms, bool multidex
}
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
if (multidex) {
// R8 currently gives: The rule `-keep public class * extends java.lang.annotation.Annotation { *; }` uses extends but actually matches implements.
Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, " 1 Warning(s)"), "Should have no more than 1 MSBuild warnings.");
} else {
Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, " 0 Warning(s)"), "Should have no MSBuild warnings.");
}
Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, " 0 Warning(s)"), "Should have no MSBuild warnings.");
Assert.IsFalse (StringAssertEx.ContainsText (b.LastBuildOutput, "Warning: end of file not at end of a line"),
"Should not get a warning from the <CompileNativeAssembly/> task.");
var lockFile = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, ".__lock");
Expand Down Expand Up @@ -1164,6 +1159,8 @@ XamarinAndroidApplicationProject CreateMultiDexRequiredApplication (string debug
[Category ("Minor")]
public void BuildApplicationRequiresMultiDex ([Values ("dx", "d8")] string dexTool)
{
if (dexTool == "d8")
Assert.Ignore ("The build currently *succeeds* with d8, when API 21 is our minimum.");
var proj = CreateMultiDexRequiredApplication ();
proj.DexTool = dexTool;
using (var b = CreateApkBuilder ()) {
Expand All @@ -1185,29 +1182,31 @@ public void CreateMultiDexWithSpacesInConfig ([Values ("dx", "d8")] string dexTo
}

[Test]
[TestCaseSource (nameof (JackFlagAndFxVersion))]
public void BuildMultiDexApplication (bool useJackAndJill, string fxVersion)
public void BuildMultiDexApplication ([Values ("dx", "d8")] string dexTool)
{
var proj = CreateMultiDexRequiredApplication ();
proj.UseLatestPlatformSdk = false;
proj.DexTool = dexTool;
proj.SetProperty ("AndroidEnableMultiDex", "True");
string intermediateDir = proj.IntermediateOutputPath;
if (IsWindows) {
proj.SetProperty ("AppendTargetFrameworkToIntermediateOutputPath", "True");
}

using (var b = CreateApkBuilder (Path.Combine ("temp", TestName), false, false)) {
proj.TargetFrameworkVersion = b.LatestTargetFrameworkVersion ();

string intermediateDir;
if (IsWindows) {
intermediateDir = Path.Combine (intermediateDir, proj.TargetFrameworkAbbreviated);
intermediateDir = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, proj.TargetFrameworkAbbreviated);
} else {
intermediateDir = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
}
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
Assert.IsTrue (File.Exists (Path.Combine (Root, b.ProjectDirectory, intermediateDir, "android/bin/classes.dex")),
"multidex-ed classes.zip exists");
FileAssert.Exists (Path.Combine (intermediateDir, "android", "bin", "classes.dex"));

if (proj.DexTool != "d8") {
var multidexKeepPath = Path.Combine (Root, b.ProjectDirectory, intermediateDir, "multidex.keep");
Assert.IsTrue (File.Exists (multidexKeepPath), "multidex.keep exists");
var multidexKeepPath = Path.Combine (intermediateDir, "multidex.keep");
FileAssert.Exists (multidexKeepPath);
Assert.IsTrue (File.ReadAllLines (multidexKeepPath).Length > 1, "multidex.keep must contain more than one line.");
}

Expand Down

0 comments on commit 64d0c0c

Please sign in to comment.