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
36 changes: 30 additions & 6 deletions src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,25 @@ public class Aapt : AsyncTask
Dictionary<string,string> resource_name_case_map = new Dictionary<string,string> ();
AssemblyIdentityMap assemblyMap = new AssemblyIdentityMap ();

struct OutputLine {
public string Line;
public bool StdError;

public OutputLine (string line, bool stdError)
{
Line = line;
StdError = stdError;
}
}

bool ManifestIsUpToDate (string manifestFile)
{
return !String.IsNullOrEmpty (AndroidComponentResgenFlagFile) &&
File.Exists (AndroidComponentResgenFlagFile) && File.Exists (manifestFile) &&
File.GetLastWriteTime (AndroidComponentResgenFlagFile) > File.GetLastWriteTime (manifestFile);
}

bool RunAapt (string commandLine)
bool RunAapt (string commandLine, IList<OutputLine> output)
{
var stdout_completed = new ManualResetEvent (false);
var stderr_completed = new ManualResetEvent (false);
Expand All @@ -119,13 +130,13 @@ bool RunAapt (string commandLine)
using (var proc = new Process ()) {
proc.OutputDataReceived += (sender, e) => {
if (e.Data != null)
LogMessage (e.Data, MessageImportance.Normal);
output.Add (new OutputLine (e.Data, stdError: false));
else
stdout_completed.Set ();
};
proc.ErrorDataReceived += (sender, e) => {
if (e.Data != null)
LogEventsFromTextOutput (e.Data, MessageImportance.Normal);
output.Add (new OutputLine (e.Data, stdError: true));
else
stderr_completed.Set ();
};
Expand All @@ -151,7 +162,16 @@ bool RunAapt (string commandLine)

bool ExecuteForAbi (string cmd, string currentResourceOutputFile)
{
var ret = RunAapt (cmd);
var output = new List<OutputLine> ();
var ret = RunAapt (cmd, output);
var success = File.Exists (Path.Combine (JavaDesignerOutputDirectory, "R.java"));
foreach (var line in output) {
if (line.StdError) {
LogEventsFromTextOutput (line.Line, MessageImportance.Normal, success);
} else {
LogMessage (line.Line, MessageImportance.Normal);
}
}
if (ret && !string.IsNullOrEmpty (currentResourceOutputFile)) {
var tmpfile = currentResourceOutputFile + ".bk";
MonoAndroidHelper.CopyIfZipChanged (tmpfile, currentResourceOutputFile);
Expand Down Expand Up @@ -362,7 +382,7 @@ protected string GenerateFullPathToTool ()
return Path.Combine (ToolPath, string.IsNullOrEmpty (ToolExe) ? ToolName : ToolExe);
}

protected void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance)
protected void LogEventsFromTextOutput (string singleLine, MessageImportance messageImportance, bool apptResult)
{
if (string.IsNullOrEmpty (singleLine))
return;
Expand Down Expand Up @@ -399,7 +419,11 @@ protected void LogEventsFromTextOutput (string singleLine, MessageImportance mes
}
}

LogError ("APT0000", string.Format("{0} \"{1}\".", singleLine.Trim(), singleLine.Substring(singleLine.LastIndexOfAny(new char[] { '\\', '/' }) + 1)), ToolName);
if (!apptResult) {
LogError ("APT0000", string.Format ("{0} \"{1}\".", singleLine.Trim (), singleLine.Substring (singleLine.LastIndexOfAny (new char [] { '\\', '/' }) + 1)), ToolName);
} else {
LogWarning (singleLine);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public IEnumerator GetEnumerator ()
/*expectedLevel*/ "",
/*expectedMessage*/ "max res 10, skipping values-sw600dp-land"
};
yield return new object [] {
/*message*/ "max res 10, skipping values-sw720dp-land-v13",
/*expectedToMatch*/ true,
/*expectedFile*/ "",
/*expectedLine*/ "",
/*expectedLevel*/ "",
/*expectedMessage*/ "max res 10, skipping values-sw720dp-land-v13"
};
yield return new object [] {
/*message*/ "Error: unable to generate entry for resource data",
/*expectedToMatch*/ true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ public void ReportAaptErrorsInOriginalFileName ()
}
}

[Test]
public void ReportAaptWarningsForBlankLevel ()
{
//This test should get the warning `Invalid file name: must contain only [a-z0-9_.]`
// However, <Aapt /> still fails due to aapt failing, Resource.designer.cs is not generated
var proj = new XamarinAndroidApplicationProject ();
proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\drawable\\Image (1).png") {
BinaryContent = () => XamarinAndroidCommonProject.icon_binary_mdpi
});
using (var b = CreateApkBuilder ("temp/ReportAaptWarningsForBlankLevel")) {
b.ThrowOnBuildFailure = false;
Assert.IsFalse (b.Build (proj), "Build should have failed.");
StringAssertEx.Contains ("APT0000", b.LastBuildOutput, "An error message with a blank \"level\", should be reported as an error!");
Assert.IsTrue (b.Clean (proj), "Clean should have succeeded.");
}
}

[Test]
public void RepetiviteBuildUpdateSingleResource ()
{
Expand Down