Add option to compile dex for a Java library

Currently Soong will only compile a Java library into dex if the
library has device support and is installable. For our use case of
inspecting the dex at build time this is not sufficient. Add a new
"compile_dex" device property which forces the creation of a dex
rule. In this case, the class jar remains the output file of the
module.

Bug: 79409988
Test: on related CL
Change-Id: Ia908a47148a03a0bdb0da4315cce6efc86c51865
diff --git a/java/java.go b/java/java.go
index e87a990..00d5263 100644
--- a/java/java.go
+++ b/java/java.go
@@ -192,6 +192,9 @@
 	// If true, export a copy of the module as a -hostdex module for host testing.
 	Hostdex *bool
 
+	// If set to true, compile dex regardless of installable.  Defaults to false.
+	Compile_dex *bool
+
 	Dex_preopt struct {
 		// If false, prevent dexpreopting and stripping the dex file from the final jar.  Defaults to
 		// true.
@@ -1134,11 +1137,15 @@
 		outputFile = j.instrument(ctx, flags, outputFile, jarName)
 	}
 
-	if ctx.Device() && j.installable() {
-		outputFile = j.compileDex(ctx, flags, outputFile, jarName)
+	if ctx.Device() && j.createDexRule() {
+		var dexOutputFile android.Path
+		dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
 		if ctx.Failed() {
 			return
 		}
+		if j.installable() {
+			outputFile = dexOutputFile
+		}
 	}
 	ctx.CheckbuildFile(outputFile)
 	j.outputFile = outputFile
@@ -1213,6 +1220,10 @@
 	return BoolDefault(j.properties.Installable, true)
 }
 
+func (j *Module) createDexRule() bool {
+	return Bool(j.deviceProperties.Compile_dex) || j.installable()
+}
+
 var _ Dependency = (*Library)(nil)
 
 func (j *Module) HeaderJars() android.Paths {