From 69f4b082b9691130c7f1f449a06394f155fddded Mon Sep 17 00:00:00 2001 From: Sorin Basca Date: Mon, 9 May 2022 13:55:11 +0100 Subject: [PATCH] Strip annotations from library stubs Bug: 222743634 Test: m Change-Id: Ic44bd7c4c163b723295eb369664432d3651b8597 --- java/core-libraries/Android.bp | 60 ++++++++++++++++++- .../jarjar-strip-annotations-rules.txt | 4 ++ 2 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 java/core-libraries/jarjar-strip-annotations-rules.txt diff --git a/java/core-libraries/Android.bp b/java/core-libraries/Android.bp index cf3974601..513c6061b 100644 --- a/java/core-libraries/Android.bp +++ b/java/core-libraries/Android.bp @@ -138,11 +138,29 @@ java_library { }, } +// Same as core-module-lib-stubs-for-system-modules, but android annotations are +// stripped. This is used by the Java toolchain, while the annotated stub is to +// be used by Kotlin one. +java_library { + name: "core-module-lib-stubs-for-system-modules-no-annotations", + visibility: ["//visibility:private"], + static_libs: [ + "core-module-lib-stubs-for-system-modules", + ], + sdk_version: "none", + system_modules: "none", + dist: { + dest: "system-modules/module-lib/core-for-system-modules-no-annotations.jar", + targets: dist_targets, + }, + jarjar_rules: "jarjar-strip-annotations-rules.txt", +} + // Used when compiling higher-level code with sdk_version "module_current" java_system_modules { name: "core-module-lib-stubs-system-modules", libs: [ - "core-module-lib-stubs-for-system-modules", + "core-module-lib-stubs-for-system-modules-no-annotations", ], visibility: ["//visibility:public"], } @@ -174,6 +192,24 @@ java_library { patch_module: "java.base", } +// Same as legacy.core.platform.api.stubs, but android annotations are +// stripped. This is used by the Java toolchain, while the annotated stub is to +// be used by Kotlin one. +java_library { + name: "legacy.core.platform.api.no.annotations.stubs", + visibility: core_platform_visibility, + hostdex: true, + compile_dex: true, + + sdk_version: "none", + system_modules: "none", + static_libs: [ + "legacy.core.platform.api.stubs", + ], + patch_module: "java.base", + jarjar_rules: "jarjar-strip-annotations-rules.txt", +} + java_library { name: "stable.core.platform.api.stubs", visibility: core_platform_visibility, @@ -191,12 +227,30 @@ java_library { patch_module: "java.base", } +// Same as stable.core.platform.api.stubs, but android annotations are +// stripped. This is used by the Java toolchain, while the annotated stub is to +// be used by Kotlin one. +java_library { + name: "stable.core.platform.api.no.annotations.stubs", + visibility: core_platform_visibility, + hostdex: true, + compile_dex: true, + + sdk_version: "none", + system_modules: "none", + static_libs: [ + "stable.core.platform.api.stubs", + ], + patch_module: "java.base", + jarjar_rules: "jarjar-strip-annotations-rules.txt", +} + // Used when compiling higher-level code against *.core.platform.api.stubs. java_system_modules { name: "legacy-core-platform-api-stubs-system-modules", visibility: core_platform_visibility, libs: [ - "legacy.core.platform.api.stubs", + "legacy.core.platform.api.no.annotations.stubs", // This one is not on device but it's needed when javac compiles code // containing lambdas. "core-lambda-stubs-for-system-modules", @@ -212,7 +266,7 @@ java_system_modules { name: "stable-core-platform-api-stubs-system-modules", visibility: core_platform_visibility, libs: [ - "stable.core.platform.api.stubs", + "stable.core.platform.api.no.annotations.stubs", // This one is not on device but it's needed when javac compiles code // containing lambdas. "core-lambda-stubs-for-system-modules", diff --git a/java/core-libraries/jarjar-strip-annotations-rules.txt b/java/core-libraries/jarjar-strip-annotations-rules.txt new file mode 100644 index 000000000..a1c261b9a --- /dev/null +++ b/java/core-libraries/jarjar-strip-annotations-rules.txt @@ -0,0 +1,4 @@ +strip-annotation android.annotation.NotNull +strip-annotation android.annotation.Nullable +strip-annotation androidx.annotation.RecentlyNonNull +strip-annotation androidx.annotation.RecentlyNullable