Put kotlin classes in header jar
If a module has kotlin sources the compiled kotlin clsases must be put
in the header jar for anything that depends on the module to use.
Bug: 113153312
Test: m checkbuild
Change-Id: Ibc44e9a97655937315b03b05e51e09c2954d7008
diff --git a/java/java.go b/java/java.go
index e20b8b3..7f82c77 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1013,8 +1013,6 @@
srcJars = append(srcJars, deps.srcJars...)
srcJars = append(srcJars, extraSrcJars...)
- var jars android.Paths
-
jarName := ctx.ModuleName() + ".jar"
javaSrcFiles := srcFiles.FilterByExt(".java")
@@ -1029,6 +1027,8 @@
var stripFiles []string
+ var kotlinJars android.Paths
+
if srcFiles.HasExt(".kt") {
// If there are kotlin files, compile them first but pass all the kotlin and java files
// kotlinc will use the java files to resolve types referenced by the kotlin files, but
@@ -1059,7 +1059,7 @@
flags.classpath = append(flags.classpath, kotlinJar)
// Jar kotlin classes into the final jar after javac
- jars = append(jars, kotlinJar)
+ kotlinJars = append(kotlinJars, kotlinJar)
if Bool(j.properties.Renamed_kotlin_stdlib) {
// Remove any kotlin-reflect related files
@@ -1070,10 +1070,12 @@
} else {
// Only add kotlin-stdlib if not using (on-device) renamed stdlib
// (it's expected to be on device bootclasspath)
- jars = append(jars, deps.kotlinStdlib...)
+ kotlinJars = append(kotlinJars, deps.kotlinStdlib...)
}
}
+ jars := append(android.Paths(nil), kotlinJars...)
+
// Store the list of .java files that was passed to javac
j.compiledJavaSrcs = uniqueSrcFiles
j.compiledSrcJars = srcJars
@@ -1089,7 +1091,7 @@
j.properties.Javac_shard_size)
}
}
- j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName)
+ j.headerJarFile = j.compileJavaHeader(ctx, uniqueSrcFiles, srcJars, deps, flags, jarName, kotlinJars)
if ctx.Failed() {
return
}
@@ -1296,7 +1298,7 @@
}
func (j *Module) compileJavaHeader(ctx android.ModuleContext, srcFiles, srcJars android.Paths,
- deps deps, flags javaBuilderFlags, jarName string) android.Path {
+ deps deps, flags javaBuilderFlags, jarName string, extraJars android.Paths) android.Path {
var jars android.Paths
if len(srcFiles) > 0 || len(srcJars) > 0 {
@@ -1309,6 +1311,8 @@
jars = append(jars, turbineJar)
}
+ jars = append(jars, extraJars...)
+
// Combine any static header libraries into classes-header.jar. If there is only
// one input jar this step will be skipped.
var headerJar android.Path