Install AndroidApp only when needed

When an android_app is (directly or transitively) included in an APEX,
multiple variants of the app is created. The problem was that all the
variants were unconditionally installed to the device, which resulted in
duplicated targets. Fixing the problem by not installing the app when it
is included in APEX.

Bug: 144387414
Bug: 144135069
Test: m
Test: OUT_DIR=out DIST_DIR=out/dist build/soong/scripts/build-ndk-prebuilts.sh
Change-Id: Ibcc1096e30bc55a70ddc592490805f447e185eae
diff --git a/java/app.go b/java/app.go
index e9ef9eb..30cd6cb 100644
--- a/java/app.go
+++ b/java/app.go
@@ -498,9 +498,11 @@
 	a.bundleFile = bundleFile
 
 	// Install the app package.
-	ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile)
-	for _, extra := range a.extraOutputFiles {
-		ctx.InstallFile(a.installDir, extra.Base(), extra)
+	if (Bool(a.Module.properties.Installable) || ctx.Host()) && a.IsForPlatform() {
+		ctx.InstallFile(a.installDir, a.outputFile.Base(), a.outputFile)
+		for _, extra := range a.extraOutputFiles {
+			ctx.InstallFile(a.installDir, extra.Base(), extra)
+		}
 	}
 }