diff --git a/java/base.go b/java/base.go index e1c2386ff..3d7d3de01 100644 --- a/java/base.go +++ b/java/base.go @@ -1946,19 +1946,22 @@ func (j *providesTransitiveHeaderJars) collectTransitiveHeaderJars(ctx android.M } dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) - if dep.TransitiveLibsHeaderJars != nil { - transitiveLibs = append(transitiveLibs, dep.TransitiveLibsHeaderJars) - } - if dep.TransitiveStaticLibsHeaderJars != nil { - transitiveStaticLibs = append(transitiveStaticLibs, dep.TransitiveStaticLibsHeaderJars) - } - tag := ctx.OtherModuleDependencyTag(module) _, isUsesLibDep := tag.(usesLibraryDependencyTag) if tag == libTag || tag == r8LibraryJarTag || isUsesLibDep { directLibs = append(directLibs, dep.HeaderJars...) } else if tag == staticLibTag { directStaticLibs = append(directStaticLibs, dep.HeaderJars...) + } else { + // Don't propagate transitive libs for other kinds of dependencies. + return + } + + if dep.TransitiveLibsHeaderJars != nil { + transitiveLibs = append(transitiveLibs, dep.TransitiveLibsHeaderJars) + } + if dep.TransitiveStaticLibsHeaderJars != nil { + transitiveStaticLibs = append(transitiveStaticLibs, dep.TransitiveStaticLibsHeaderJars) } }) j.transitiveLibsHeaderJars = android.NewDepSet(android.POSTORDER, directLibs, transitiveLibs)