Rearrange manifest file handling in merge_zips and soong_zip

Jar always puts default MANIFEST.MF files in if none was specified.
Copying that behavior in soong_zip causes problems with merge_zips,
because it ends up taking the default manifest from the classes.jar
instead of the user's manifest from res.jar.  We don't want the
user's manifest in the classes.jar, otherwise a change to the
manifest will cause all the class files to rebuild.  Instead,
move the manifest insertion to the final merge_zips stage.

Test: m -j checkbuild
Change-Id: Id6376961dbaf743c2fb92843f9bdf2e44b963be0
diff --git a/java/java.go b/java/java.go
index b4ce35e..d7b5847 100644
--- a/java/java.go
+++ b/java/java.go
@@ -385,11 +385,9 @@
 	}
 
 	resourceJarSpecs := ResourceDirsToJarSpecs(ctx, j.properties.Resource_dirs, j.properties.Exclude_resource_dirs)
-	manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
-
-	if len(resourceJarSpecs) > 0 || manifest.Valid() {
+	if len(resourceJarSpecs) > 0 {
 		// Combine classes + resources into classes-full-debug.jar
-		resourceJar := TransformResourcesToJar(ctx, resourceJarSpecs, manifest, extraJarDeps)
+		resourceJar := TransformResourcesToJar(ctx, resourceJarSpecs, extraJarDeps)
 		if ctx.Failed() {
 			return
 		}
@@ -399,9 +397,11 @@
 
 	jars = append(jars, deps.staticJars...)
 
+	manifest := android.OptionalPathForModuleSrc(ctx, j.properties.Manifest)
+
 	// Combine the classes built from sources, any manifests, and any static libraries into
 	// classes-combined.jar.  If there is only one input jar this step will be skipped.
-	outputFile := TransformJarsToJar(ctx, "classes-combined.jar", jars)
+	outputFile := TransformJarsToJar(ctx, "classes.jar", jars, manifest, false)
 
 	if j.properties.Jarjar_rules != nil {
 		jarjar_rules := android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules)
@@ -616,7 +616,7 @@
 func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
 	j.classpathFiles = android.PathsForModuleSrc(ctx, j.properties.Jars)
 
-	j.combinedClasspathFile = TransformJarsToJar(ctx, "classes.jar", j.classpathFiles)
+	j.combinedClasspathFile = TransformJarsToJar(ctx, "classes.jar", j.classpathFiles, android.OptionalPath{}, false)
 }
 
 var _ Dependency = (*Import)(nil)