Support native SOs in ravenwood runtime

Bug: 323931246
Test: m nothing --no-skip-soong-tests
Test: Manual test using a locally created build rule

Merged-in: Icd15d63c29560dc219dba07cc9db2a5e1b883532
Change-Id: Icd15d63c29560dc219dba07cc9db2a5e1b883532
diff --git a/java/ravenwood.go b/java/ravenwood.go
index e362003..dcb5c8b 100644
--- a/java/ravenwood.go
+++ b/java/ravenwood.go
@@ -30,13 +30,27 @@
 }
 
 var ravenwoodTag = dependencyTag{name: "ravenwood"}
+var ravenwoodJniTag = dependencyTag{name: "ravenwood-jni"}
 
 const ravenwoodUtilsName = "ravenwood-utils"
 const ravenwoodRuntimeName = "ravenwood-runtime"
 
+func getLibPath(archType android.ArchType) string {
+	if archType.Multilib == "lib64" {
+		return "lib64"
+	}
+	return "lib"
+}
+
+type ravenwoodTestProperties struct {
+	Jni_libs []string
+}
+
 type ravenwoodTest struct {
 	Library
 
+	ravenwoodTestProperties ravenwoodTestProperties
+
 	testProperties testProperties
 	testConfig     android.Path
 
@@ -48,7 +62,7 @@
 	module := &ravenwoodTest{}
 
 	module.addHostAndDeviceProperties()
-	module.AddProperties(&module.testProperties)
+	module.AddProperties(&module.testProperties, &module.ravenwoodTestProperties)
 
 	module.Module.dexpreopter.isTest = true
 	module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true)
@@ -86,6 +100,11 @@
 			ctx.AddVariationDependencies(nil, libTag, lib)
 		}
 	}
+
+	// Add jni libs
+	for _, lib := range r.ravenwoodTestProperties.Jni_libs {
+		ctx.AddVariationDependencies(ctx.Config().BuildOSTarget.Variations(), ravenwoodJniTag, lib)
+	}
 }
 
 func (r *ravenwoodTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -116,7 +135,15 @@
 	installConfig := ctx.InstallFile(installPath, ctx.ModuleName()+".config", r.testConfig)
 	installDeps = append(installDeps, installConfig)
 
-	// Finally install our JAR with all dependencies
+	// Depend on the JNI libraries.
+	soInstallPath := installPath.Join(ctx, getLibPath(r.forceArchType))
+	for _, dep := range ctx.GetDirectDepsWithTag(ravenwoodJniTag) {
+		file := android.OutputFileForModule(ctx, dep, "")
+		installJni := ctx.InstallFile(soInstallPath, file.Base(), file)
+		installDeps = append(installDeps, installJni)
+	}
+
+	// Install our JAR with all dependencies
 	ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.outputFile, installDeps...)
 }
 
@@ -137,6 +164,8 @@
 
 type ravenwoodLibgroupProperties struct {
 	Libs []string
+
+	Jni_libs []string
 }
 
 type ravenwoodLibgroup struct {
@@ -172,6 +201,9 @@
 	for _, lib := range r.ravenwoodLibgroupProperties.Libs {
 		ctx.AddVariationDependencies(nil, ravenwoodTag, lib)
 	}
+	for _, lib := range r.ravenwoodLibgroupProperties.Jni_libs {
+		ctx.AddVariationDependencies(ctx.Config().BuildOSTarget.Variations(), ravenwoodJniTag, lib)
+	}
 }
 
 func (r *ravenwoodLibgroup) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -185,6 +217,11 @@
 		libJar := android.OutputFileForModule(ctx, libModule, "")
 		ctx.InstallFile(installPath, lib+".jar", libJar)
 	}
+	soInstallPath := android.PathForModuleInstall(ctx, r.BaseModuleName()).Join(ctx, getLibPath(r.forceArchType))
+	for _, dep := range ctx.GetDirectDepsWithTag(ravenwoodJniTag) {
+		file := android.OutputFileForModule(ctx, dep, "")
+		ctx.InstallFile(soInstallPath, file.Base(), file)
+	}
 
 	// Normal build should perform install steps
 	ctx.Phony(r.BaseModuleName(), android.PathForPhony(ctx, r.BaseModuleName()+"-install"))