Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Fix Aapt task to emit warnings (#1178)
Browse files Browse the repository at this point in the history
Fixes: #1134

Commit 23c5801 reworked `<Aapt/>` to emit warnings if the required
output file did exist. If it didn't we should emit errors.
There was one slight problem with this, we were checking the
wrong file. We should have been checking for the temp
`packaged_resources` file rather than `R.txt` (which will
always exist after an initial build).

This commit fixes that and adds a unit test. Note the in order
to create the senario we need to have a `$(TargetFrameworkVersion)`
which is `v8.0`. We currently only build `v1.0` and `v8.1` for
PR builds. So the test checks to see if that target framework is
available. If not the test will be ignored.
  • Loading branch information
dellis1972 authored and jonpryor committed Jan 12, 2018
1 parent a66e8b8 commit 9372683
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ bool ExecuteForAbi (string cmd, string currentResourceOutputFile)
{
var output = new List<OutputLine> ();
var ret = RunAapt (cmd, output);
var success = File.Exists (Path.Combine (JavaDesignerOutputDirectory, "R.java"));
var success = !string.IsNullOrEmpty (currentResourceOutputFile)
? File.Exists (Path.Combine (currentResourceOutputFile + ".bk"))
: ret;
foreach (var line in output) {
if (line.StdError) {
LogEventsFromTextOutput (line.Line, MessageImportance.Normal, success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,34 @@ public void BuildAppWithManagedResourceParserAndLibraries ()
}
}

[Test]
public void CheckMaxResWarningIsEmittedAsAWarning()
{
var path = Path.Combine ("temp", TestName);
var proj = new XamarinAndroidApplicationProject () {
TargetFrameworkVersion = "v8.0",
UseLatestPlatformSdk = false,
IsRelease = true,
OtherBuildItems = {
new BuildItem.Folder ("Resources\\values-v27\\") {
},
},
};
proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\values-v27\\Strings.xml") {
TextContent = () => @"<?xml version=""1.0"" encoding=""utf-8""?>
<resources>
<string name=""test"" >Test</string>
</resources>",
});
using (var builder = CreateApkBuilder (path)) {
if (!builder.TargetFrameworkExists (proj.TargetFrameworkVersion)) {
Assert.Ignore ($"Skipping Test. TargetFrameworkVersion {proj.TargetFrameworkVersion} was not available.");
}
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
StringAssertEx.Contains ("warning : max res 26, skipping values-v27", builder.LastBuildOutput, "Build output should contain a warning about 'max res 26, skipping values-v27'");
}
}

[Test]
public void CheckDefaultTranslationWarnings ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ public string LatestTargetFrameworkVersion () {
return "v" + latest.ToString (2);
}

public bool TargetFrameworkExists (string targetFramework)
{
var path = Path.Combine (FrameworkLibDirectory, "xbuild-frameworks", "MonoAndroid", targetFramework);
if (!Directory.Exists (path)) {
return false;
}
return true;
}


public string Root {
get {
Expand Down

0 comments on commit 9372683

Please sign in to comment.