Revert "Revert "Add dex file writer to dexlayout tool.""

This reverts commit fd1a6c2a08ca3e2476b7424b9b0fa58e73b29e87.

Fixed output being clobbered during DexLayoutTest.DexFileOutput.
Option added to put dex output file in scratch directory.

Bug: 29921113
Test: mm test-art-host-gtest-dexlayout_test

Change-Id: I9e6b139cf06aaa39c83ad1e74329db266464a8e4
diff --git a/dexlayout/dex_ir_builder.cc b/dexlayout/dex_ir_builder.cc
index 599f48b..68ff2a2 100644
--- a/dexlayout/dex_ir_builder.cc
+++ b/dexlayout/dex_ir_builder.cc
@@ -70,6 +70,8 @@
   for (uint32_t i = 0; i < dex_file.NumClassDefs(); ++i) {
     collections.CreateClassDef(dex_file, i);
   }
+  // MapItem.
+  collections.SetMapItemOffset(disk_header.map_off_);
 
   CheckAndSetRemainingOffsets(dex_file, &collections);
 
@@ -124,7 +126,7 @@
         collections->SetAnnotationSetRefListsOffset(item->offset_);
         break;
       case DexFile::kDexTypeAnnotationSetItem:
-        collections->SetAnnotationSetOffset(item->offset_);
+        collections->SetAnnotationSetItemsOffset(item->offset_);
         break;
       case DexFile::kDexTypeClassDataItem:
         collections->SetClassDatasOffset(item->offset_);
@@ -136,16 +138,16 @@
         collections->SetStringDatasOffset(item->offset_);
         break;
       case DexFile::kDexTypeDebugInfoItem:
-        collections->SetDebugInfoOffset(item->offset_);
+        collections->SetDebugInfoItemsOffset(item->offset_);
         break;
       case DexFile::kDexTypeAnnotationItem:
-        collections->SetAnnotationOffset(item->offset_);
+        collections->SetAnnotationItemsOffset(item->offset_);
         break;
       case DexFile::kDexTypeEncodedArrayItem:
-        collections->SetEncodedArrayOffset(item->offset_);
+        collections->SetEncodedArrayItemsOffset(item->offset_);
         break;
       case DexFile::kDexTypeAnnotationsDirectoryItem:
-        collections->SetAnnotationsDirectoryOffset(item->offset_);
+        collections->SetAnnotationsDirectoryItemsOffset(item->offset_);
         break;
       default:
         LOG(ERROR) << "Unknown map list item type.";