Add static_libs property in java_api_library soong module
Package private stub annotations are not part of any API surfaces, but
are included in the `android_<API_SURFACE_NAME>_stubs_current`. Since
these cannot be included in the java_api_library by api_contributions,
add static_libs property to statically include jars in the output jar
file.
Test: m
Change-Id: Icb4401f29079ba32df4c192943a7e8814599d9ba
diff --git a/java/java.go b/java/java.go
index 659f98a..a003162 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1633,6 +1633,10 @@
// List of shared java libs that this module has dependencies to and
// should be passed as classpath in javac invocation
Libs []string
+
+ // List of java libs that this module has static dependencies to and will be
+ // passed in metalava invocation
+ Static_libs []string
}
func ApiLibraryFactory() android.Module {
@@ -1705,6 +1709,7 @@
ctx.AddDependency(ctx.Module(), javaApiContributionTag, apiContributionName)
}
ctx.AddVariationDependencies(nil, libTag, al.properties.Libs...)
+ ctx.AddVariationDependencies(nil, staticLibTag, al.properties.Static_libs...)
}
func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -1724,6 +1729,7 @@
var srcFiles android.Paths
var classPaths android.Paths
+ var staticLibs android.Paths
ctx.VisitDirectDeps(func(dep android.Module) {
tag := ctx.OtherModuleDependencyTag(dep)
switch tag {
@@ -1737,6 +1743,9 @@
case libTag:
provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo)
classPaths = append(classPaths, provider.HeaderJars...)
+ case staticLibTag:
+ provider := ctx.OtherModuleProvider(dep, JavaInfoProvider).(JavaInfo)
+ staticLibs = append(staticLibs, provider.HeaderJars...)
}
})
@@ -1761,7 +1770,7 @@
FlagWithArg("-D ", stubsDir.String())
rule.Build("metalava", "metalava merged")
-
+ compiledStubs := android.PathForModuleOut(ctx, ctx.ModuleName(), "stubs.jar")
al.stubsJar = android.PathForModuleOut(ctx, ctx.ModuleName(), "android.jar")
var flags javaBuilderFlags
@@ -1769,9 +1778,17 @@
flags.javacFlags = strings.Join(al.properties.Javacflags, " ")
flags.classpath = classpath(classPaths)
- TransformJavaToClasses(ctx, al.stubsJar, 0, android.Paths{},
+ TransformJavaToClasses(ctx, compiledStubs, 0, android.Paths{},
android.Paths{al.stubsSrcJar}, flags, android.Paths{})
+ builder := android.NewRuleBuilder(pctx, ctx)
+ builder.Command().
+ BuiltTool("merge_zips").
+ Output(al.stubsJar).
+ Inputs(android.Paths{compiledStubs}).
+ Inputs(staticLibs)
+ builder.Build("merge_zips", "merge jar files")
+
ctx.Phony(ctx.ModuleName(), al.stubsJar)
ctx.SetProvider(JavaInfoProvider, JavaInfo{