AAPT2: Fix multi APK output

- Ensure that the output directory exists before generating APKs
- Only use the file name (and not the path) for creating output
  file names

Test: manually ran optimize command

Change-Id: I5f5ecb5dcec4d17cdbca5709f2dd17e6d53df986
diff --git a/tools/aapt2/optimize/MultiApkGenerator.cpp b/tools/aapt2/optimize/MultiApkGenerator.cpp
index f413ee9..8316264 100644
--- a/tools/aapt2/optimize/MultiApkGenerator.cpp
+++ b/tools/aapt2/optimize/MultiApkGenerator.cpp
@@ -46,7 +46,7 @@
   // TODO(safarmer): Handle APK version codes for the generated APKs.
   // TODO(safarmer): Handle explicit outputs/generating an output file list for other tools.
 
-  const std::string& apk_path = apk_->GetSource().path;
+  const std::string& apk_path = file::GetFilename(apk_->GetSource().path).to_string();
   const StringPiece ext = file::GetExtension(apk_path);
   const std::string base_name = apk_path.substr(0, apk_path.rfind(ext.to_string()));
 
@@ -122,10 +122,14 @@
 
     std::unique_ptr<ResourceTable> table = apk_->GetResourceTable()->Clone();
 
+
     TableSplitter splitter{{}, splits};
     splitter.SplitTable(table.get());
 
     std::string out = out_dir;
+    if (!file::mkdirs(out)) {
+      context_->GetDiagnostics()->Warn(DiagMessage() << "could not create out dir: " << out);
+    }
     file::AppendPath(&out, artifact_name.value());
 
     std::unique_ptr<IArchiveWriter> writer =