Don't add flattened files apex as dependencies of an image apex

The image apex does not need all the files that make up a flattened
apex.

Bug: 254205429
Test: go tests
Change-Id: Iff05f2d01f11397bc9e9bf31868112575268969b
diff --git a/apex/androidmk.go b/apex/androidmk.go
index 3373211..ea42c3c 100644
--- a/apex/androidmk.go
+++ b/apex/androidmk.go
@@ -339,14 +339,14 @@
 func (a *apexBundle) androidMkForType() android.AndroidMkData {
 	return android.AndroidMkData{
 		Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
-			moduleNames := []string{}
 			apexType := a.properties.ApexType
-			if a.installable() {
-				apexName := proptools.StringDefault(a.properties.Apex_name, name)
-				moduleNames = a.androidMkForFiles(w, name, apexName, moduleDir, data)
-			}
 
 			if apexType == flattenedApex {
+				var moduleNames []string = nil
+				if a.installable() {
+					apexName := proptools.StringDefault(a.properties.Apex_name, name)
+					moduleNames = a.androidMkForFiles(w, name, apexName, moduleDir, data)
+				}
 				// Only image APEXes can be flattened.
 				fmt.Fprintln(w, "\ninclude $(CLEAR_VARS)")
 				fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir)
@@ -390,7 +390,7 @@
 				if len(a.overridableProperties.Overrides) > 0 {
 					fmt.Fprintln(w, "LOCAL_OVERRIDES_MODULES :=", strings.Join(a.overridableProperties.Overrides, " "))
 				}
-				a.writeRequiredModules(w, moduleNames)
+				a.writeRequiredModules(w, nil)
 
 				fmt.Fprintln(w, "include $(BUILD_PREBUILT)")