summaryrefslogtreecommitdiff
path: root/java/base.go
diff options
context:
space:
mode:
Diffstat (limited to 'java/base.go')
-rw-r--r--java/base.go66
1 files changed, 34 insertions, 32 deletions
diff --git a/java/base.go b/java/base.go
index c7702395f..f26404b8c 100644
--- a/java/base.go
+++ b/java/base.go
@@ -615,21 +615,24 @@ func (j *Module) IsStubsModule() bool {
return proptools.Bool(j.properties.Is_stubs_module)
}
-func (j *Module) CheckStableSdkVersion(ctx android.BaseModuleContext) error {
- sdkVersion := j.SdkVersion(ctx)
- if sdkVersion.Stable() {
- return nil
- }
- if sdkVersion.Kind == android.SdkCorePlatform {
- if useLegacyCorePlatformApi(ctx, j.BaseModuleName()) {
- return fmt.Errorf("non stable SDK %v - uses legacy core platform", sdkVersion)
- } else {
- // Treat stable core platform as stable.
+func CheckStableSdkVersion(ctx android.BaseModuleContext, module android.ModuleProxy) error {
+ if info, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok {
+ if info.SdkVersion.Stable() {
return nil
}
- } else {
- return fmt.Errorf("non stable SDK %v", sdkVersion)
+ if info.SdkVersion.Kind == android.SdkCorePlatform {
+ if useLegacyCorePlatformApi(ctx, android.OtherModuleProviderOrDefault(ctx, module, android.CommonModuleInfoKey).BaseModuleName) {
+ return fmt.Errorf("non stable SDK %v - uses legacy core platform", info.SdkVersion)
+ } else {
+ // Treat stable core platform as stable.
+ return nil
+ }
+ } else {
+ return fmt.Errorf("non stable SDK %v", info.SdkVersion)
+ }
}
+
+ return nil
}
// checkSdkVersions enforces restrictions around SDK dependencies.
@@ -717,10 +720,10 @@ func (j *Module) provideHiddenAPIPropertyInfo(ctx android.ModuleContext) {
// helper method for java modules to set OutputFilesProvider
func setOutputFiles(ctx android.ModuleContext, m Module) {
- ctx.SetOutputFiles(append(android.Paths{m.outputFile}, m.extraOutputFiles...), "")
- ctx.SetOutputFiles(android.Paths{m.outputFile}, android.DefaultDistTag)
- ctx.SetOutputFiles(android.Paths{m.implementationAndResourcesJar}, ".jar")
- ctx.SetOutputFiles(android.Paths{m.headerJarFile}, ".hjar")
+ ctx.SetOutputFiles(append(android.PathsIfNonNil(m.outputFile), m.extraOutputFiles...), "")
+ ctx.SetOutputFiles(android.PathsIfNonNil(m.outputFile), android.DefaultDistTag)
+ ctx.SetOutputFiles(android.PathsIfNonNil(m.implementationAndResourcesJar), ".jar")
+ ctx.SetOutputFiles(android.PathsIfNonNil(m.headerJarFile), ".hjar")
if m.dexer.proguardDictionary.Valid() {
ctx.SetOutputFiles(android.Paths{m.dexer.proguardDictionary.Path()}, ".proguard_map")
}
@@ -769,7 +772,8 @@ func (j *Module) shouldInstrumentInApex(ctx android.BaseModuleContext) bool {
apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
isJacocoAgent := ctx.ModuleName() == "jacocoagent"
- if j.DirectlyInAnyApex() && !isJacocoAgent && !apexInfo.IsForPlatform() {
+ compileDex := Bool(j.dexProperties.Compile_dex) || Bool(j.properties.Installable)
+ if compileDex && !isJacocoAgent && !apexInfo.IsForPlatform() {
if !inList(ctx.ModuleName(), config.InstrumentFrameworkModules) {
return true
} else if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
@@ -1302,6 +1306,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
ExportedPluginDisableTurbine: j.exportedDisableTurbine,
StubsLinkType: j.stubsLinkType,
AconfigIntermediateCacheOutputPaths: deps.aconfigProtoFiles,
+ SdkVersion: j.SdkVersion(ctx),
})
j.outputFile = j.headerJarFile
@@ -1738,7 +1743,12 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
completeStaticLibsImplementationJarsToCombine := completeStaticLibsImplementationJars
- if j.shouldInstrument(ctx) {
+ apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
+
+ // Enable dex compilation for the APEX variants, unless it is disabled explicitly
+ compileDex := Bool(j.dexProperties.Compile_dex) || Bool(j.properties.Installable)
+
+ if j.shouldInstrument(ctx) && (!ctx.Device() || compileDex) {
instrumentedOutputFile := j.instrument(ctx, flags, outputFile, jarName, specs)
completeStaticLibsImplementationJarsToCombine = depset.New(depset.PREORDER, android.Paths{instrumentedOutputFile}, nil)
outputFile = instrumentedOutputFile
@@ -1767,19 +1777,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
j.implementationAndResourcesJar = outputFile
- // Enable dex compilation for the APEX variants, unless it is disabled explicitly
- compileDex := j.dexProperties.Compile_dex
- apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
- if j.DirectlyInAnyApex() && !apexInfo.IsForPlatform() {
- if compileDex == nil {
- compileDex = proptools.BoolPtr(true)
- }
- if j.deviceProperties.Hostdex == nil {
- j.deviceProperties.Hostdex = proptools.BoolPtr(true)
- }
- }
-
- if ctx.Device() && (Bool(j.properties.Installable) || Bool(compileDex)) {
+ if ctx.Device() && compileDex {
if j.hasCode(ctx) {
if j.shouldInstrumentStatic(ctx) {
j.dexer.extraProguardFlagsFiles = append(j.dexer.extraProguardFlagsFiles,
@@ -1938,6 +1936,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
JacocoReportClassesFile: j.jacocoReportClassesFile,
StubsLinkType: j.stubsLinkType,
AconfigIntermediateCacheOutputPaths: j.aconfigCacheFiles,
+ SdkVersion: j.SdkVersion(ctx),
})
// Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource
@@ -2331,7 +2330,10 @@ func (m *Module) getSdkLinkType(ctx android.BaseModuleContext, name string) (ret
"stable.core.platform.api.stubs",
"stub-annotations", "private-stub-annotations-jar",
"core-lambda-stubs",
- "core-generated-annotation-stubs":
+ "core-generated-annotation-stubs",
+ // jacocoagent only uses core APIs, but has to specify a non-core sdk_version so it can use
+ // a prebuilt SDK to avoid circular dependencies when it statically included in the bootclasspath.
+ "jacocoagent":
return javaCore, true
case android.SdkPublic.DefaultJavaLibraryName():
return javaSdk, true