Be more strict about unknown install <uses-library> paths.

Allow default install paths only for compatibility libraries. For other
libraries that are explicitly specified in `uses_libs` and
`optional_uses_libs` unknown install path should be an error.

Bug: 132357300
Test: lunch cf_x86_phone-userdebug && m
Change-Id: I2209c90a939a8aa46c42e13bb42d09c07e4d0895
diff --git a/java/app.go b/java/app.go
index 3dfdfdc..406894d 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1915,11 +1915,11 @@
 		if hasFrameworkLibs {
 			// Dexpreopt needs paths to the dex jars of these libraries in order to construct
 			// class loader context for dex2oat. Add them as a dependency with a special tag.
-			ctx.AddVariationDependencies(nil, usesLibTag,
+			ctx.AddVariationDependencies(nil, usesLibCompatTag,
 				"org.apache.http.legacy",
 				"android.hidl.base-V1.0-java",
 				"android.hidl.manager-V1.0-java")
-			ctx.AddVariationDependencies(nil, usesLibTag, optionalUsesLibs...)
+			ctx.AddVariationDependencies(nil, usesLibCompatTag, optionalUsesLibs...)
 		}
 	}
 }
@@ -1937,30 +1937,27 @@
 	usesLibPaths := make(dexpreopt.LibraryPaths)
 
 	if !ctx.Config().UnbundledBuild() {
-		ctx.VisitDirectDepsWithTag(usesLibTag, func(m android.Module) {
-			dep := ctx.OtherModuleName(m)
-			if lib, ok := m.(Dependency); ok {
-				buildPath := lib.DexJarBuildPath()
-				if buildPath == nil {
-					ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must"+
-						" produce a dex jar, does it have installable: true?", dep)
-					return
-				}
+		ctx.VisitDirectDeps(func(m android.Module) {
+			tag := ctx.OtherModuleDependencyTag(m)
+			if tag == usesLibTag || tag == usesLibCompatTag {
+				dep := ctx.OtherModuleName(m)
 
-				var devicePath string
-				installPath := lib.DexJarInstallPath()
-				if installPath == nil {
-					devicePath = filepath.Join("/system/framework", dep+".jar")
+				if lib, ok := m.(Dependency); ok {
+					buildPath := lib.DexJarBuildPath()
+					installPath := lib.DexJarInstallPath()
+					if installPath == nil && tag == usesLibCompatTag {
+						// assume that compatibility libraries are in /system/framework
+						installPath = android.PathForModuleInstall(ctx, "framework", dep+".jar")
+					}
+					usesLibPaths.AddLibraryPath(ctx, dep, buildPath, installPath)
+
+				} else if ctx.Config().AllowMissingDependencies() {
+					ctx.AddMissingDependencies([]string{dep})
+
 				} else {
-					devicePath = android.InstallPathToOnDevicePath(ctx, installPath.(android.InstallPath))
+					ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be "+
+						"a java library", dep)
 				}
-
-				usesLibPaths[dep] = &dexpreopt.LibraryPath{buildPath, devicePath}
-			} else if ctx.Config().AllowMissingDependencies() {
-				ctx.AddMissingDependencies([]string{dep})
-			} else {
-				ctx.ModuleErrorf("module %q in uses_libs or optional_uses_libs must be "+
-					"a java library", dep)
 			}
 		})
 	}
diff --git a/java/java.go b/java/java.go
index 0690418..c568ec4 100644
--- a/java/java.go
+++ b/java/java.go
@@ -566,6 +566,7 @@
 	certificateTag        = dependencyTag{name: "certificate"}
 	instrumentationForTag = dependencyTag{name: "instrumentation_for"}
 	usesLibTag            = dependencyTag{name: "uses-library"}
+	usesLibCompatTag      = dependencyTag{name: "uses-library-compat"}
 	extraLintCheckTag     = dependencyTag{name: "extra-lint-check"}
 )