Work around Java 9 build failures due to @Generated annotations.
Some code generation tools, notably dagger, produce output which
includes a @Generated annotation when built with javac -source 9
-target 9. This annotation is not part of any Android API, so
compilation fails.
As a workaround for this dagger behaviour, this change introduces a
stub for that annotations, available at compile time only, to keep
javac happy. (This topic should be reverted if dagger is fixed not to
use the annotation in its output.)
The upstream source for Generated.java is OpenJDK 9+181.
N.B. The problem this is fixing does not manifest in AOSP, only in
downstream branches.
Bug: 123891440
Test: EXPERIMENTAL_USE_OPENJDK9=true make droid
(cherry picked from commit 81dd1d9418f62f6888063aeec53e15d123948f0c)
Merged-In: I06ff179384160a598b70959a0b0cd82d439490ce
Change-Id: I55971ce65c74bac75b32f1258a96de7368ac97c0
diff --git a/JavaLibrary.bp b/JavaLibrary.bp
index 5f9835e..1e4407c 100644
--- a/JavaLibrary.bp
+++ b/JavaLibrary.bp
@@ -164,6 +164,7 @@
":core_oj_java_files",
":core_libart_java_files",
":openjdk_lambda_stub_files",
+ ":openjdk_generated_annotation_stub_files",
],
no_standard_libs: true,
@@ -381,6 +382,29 @@
],
}
+
+// Creates a jar that exists to satisfy javac when compiling source code that
+// contains @Generated annotations, which are produced by some code generation
+// tools (notably dagger) but aren't part of the Android API.
+// See http://b/123891440.
+java_library {
+ name: "core-generated-annotation-stubs",
+ defaults: ["libcore_java_defaults"],
+ srcs: [
+ ":openjdk_generated_annotation_stub_files",
+ ],
+ hostdex: true,
+ no_standard_libs: true,
+ libs: ["core-all"],
+ system_modules: "core-all-system-modules",
+ openjdk9: {
+ javacflags: ["--patch-module=java.base=."],
+ },
+ notice: "ojluni/NOTICE",
+ installable: false,
+ include_srcs: true,
+}
+
// A system modules definition containing the implementations for the various
// parts that make up the core library.
//