Modify Soong to utilize from-text android.jar in build
Context
- from-text android.jar files are built using Metalava, and these can be
utilized in `decodeSdkDep` so that any modules that depends on APIs
can be compiled using from-text android.jars
- This change removes dependency on source java files when compiling
stub android.jar files
Implementation
- Modify java_api_library module to create system modules using the
generated android.jar
- Replace modules in decodeSdkDep to link against java_api_library
modules
- Add --build-from-text-stub flag to hide the feature behind a flag
Test: m --build-from-text-stub
Bug: 271154441
Change-Id: I104df595edc65c0006820d5ae5b15f1fb167e190
diff --git a/java/androidmk.go b/java/androidmk.go
index a4dac80..148d7c2 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -733,3 +733,22 @@
},
}
}
+
+func (al *ApiLibrary) AndroidMkEntries() []android.AndroidMkEntries {
+ var entriesList []android.AndroidMkEntries
+
+ entriesList = append(entriesList, android.AndroidMkEntries{
+ Class: "JAVA_LIBRARIES",
+ OutputFile: android.OptionalPathForPath(al.stubsJar),
+ Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
+ ExtraEntries: []android.AndroidMkExtraEntriesFunc{
+ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
+ entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
+ entries.SetPath("LOCAL_SOONG_CLASSES_JAR", al.stubsJar)
+ entries.SetPath("LOCAL_SOONG_HEADER_JAR", al.stubsJar)
+ },
+ },
+ })
+
+ return entriesList
+}
diff --git a/java/java.go b/java/java.go
index 3707815..91193cc 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1692,6 +1692,12 @@
Flag("--color").
Flag("--quiet").
Flag("--format=v2").
+ Flag("--include-annotations").
+ // The flag makes nullability issues as warnings rather than errors by replacing
+ // @Nullable/@NonNull in the listed packages APIs with @RecentlyNullable/@RecentlyNonNull,
+ // and these packages are meant to have everything annotated
+ // @RecentlyNullable/@RecentlyNonNull.
+ FlagWithArg("--force-convert-to-warning-nullability-annotations ", "+*:-android.*:+android.icu.*:-dalvik.*").
FlagWithArg("--repeat-errors-max ", "10").
FlagWithArg("--hide ", "UnresolvedImport").
FlagWithArg("--hide ", "InvalidNullabilityOverride").
@@ -1700,6 +1706,14 @@
return cmd
}
+func (al *ApiLibrary) HeaderJars() android.Paths {
+ return android.Paths{al.stubsJar}
+}
+
+func (al *ApiLibrary) OutputDirAndDeps() (android.Path, android.Paths) {
+ return nil, nil
+}
+
func (al *ApiLibrary) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath) {
if stubsDir.Valid() {
cmd.FlagWithArg("--stubs ", stubsDir.String())
@@ -1797,7 +1811,10 @@
ctx.Phony(ctx.ModuleName(), al.stubsJar)
ctx.SetProvider(JavaInfoProvider, JavaInfo{
- HeaderJars: android.PathsIfNonNil(al.stubsJar),
+ HeaderJars: android.PathsIfNonNil(al.stubsJar),
+ ImplementationAndResourcesJars: android.PathsIfNonNil(al.stubsJar),
+ ImplementationJars: android.PathsIfNonNil(al.stubsJar),
+ AidlIncludeDirs: android.Paths{},
})
}