From 6a396c1abb4e52f5a8fed5fab204ebc7b8e16dec Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Thu, 20 Oct 2016 14:38:23 -0700 Subject: [PATCH] AAPT2: Error on uncompiled XML or PNG files in link phase Incorrectly passing text XML and unprocessed PNG files to the AAPT2 link phase should raise an error. Test: manual incorrect invocation of aapt2 Change-Id: Iab47f99bc378b5d1c4f4d87098f08243b9a4dc6a --- tools/aapt2/link/Link.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/aapt2/link/Link.cpp b/tools/aapt2/link/Link.cpp index a42d868d92cc6..6dd34e3e5f11f 100644 --- a/tools/aapt2/link/Link.cpp +++ b/tools/aapt2/link/Link.cpp @@ -1299,6 +1299,17 @@ class LinkCommand { } } return true; + } else if (util::stringEndsWith(src.path, ".xml") || + util::stringEndsWith(src.path, ".png")) { + // Since AAPT compiles these file types and appends .flat to them, seeing + // their raw extensions is a sign that they weren't compiled. + const StringPiece fileType = + util::stringEndsWith(src.path, ".xml") ? "XML" : "PNG"; + mContext->getDiagnostics()->error(DiagMessage(src) + << "uncompiled " << fileType + << " file passed as argument. Must be " + "compiled first into .flat file."); + return false; } // Ignore non .flat files. This could be classes.dex or something else that