Disable the system-modules plugin for jlink invocations.
This jlink plugin is intended to optimise startup times for Java
runtimes by embedding a pre-processed and pre-validated module graph
in the system image.
This provides no benefit on Android, since the Android runtime does
not make use of the module graph it produces. (It doesn't seem useful
on Android anyway, since the system image only contains one module,
namely java.base.)
Furthermore, the plugin causes the jlink invocation to fail when using
the jlink tool from OpenJDK 11. The issue here is the plugin uses
classes in the jdk.internal.module package to describe the module
graph; that package is not part of libcore and therefore not listed in
the module-info.java for java.base on Android; but the plugin has the
side-effect of adding the package to java.base; this causes jlink to
subsequently fail with an error "Module java.base's descriptor
indicates the set of packages is : <lots of packages>, but module
contains packages: <same packages plus jdk.internal.module>". (The
implementation of the plugin changed significantly in OpenJDK 10,
which is presumably why this issue does not occur using OpenJDK 9's
jlink.)
Therefore, it is safe and beneficial to disable the plugin.
Test: EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9=true make core-all-system-modules, using an OpenJDK 11 toolchain via OVERRIDE_ANDROID_JAVA_HOME and changing the jmod create invocation to use --module-version 11
Test: EXPERIMENTAL_JAVA_LANGUAGE_LEVEL_9=true make droid, flash to device & sanity check
Bug: 131683177
Change-Id: I52333f32c88aa85cd3652ad91d50d9927ff61daf
diff --git a/java/system_modules.go b/java/system_modules.go
index 8005360..2ec3dfb 100644
--- a/java/system_modules.go
+++ b/java/system_modules.go
@@ -42,7 +42,11 @@
`${config.MergeZipsCmd} -j ${workDir}/module.jar ${workDir}/classes.jar $in && ` +
`${config.JmodCmd} create --module-version 9 --target-platform android ` +
` --class-path ${workDir}/module.jar ${workDir}/jmod/${moduleName}.jmod && ` +
- `${config.JlinkCmd} --module-path ${workDir}/jmod --add-modules ${moduleName} --output ${outDir} && ` +
+ `${config.JlinkCmd} --module-path ${workDir}/jmod --add-modules ${moduleName} --output ${outDir} ` +
+ // Note: The system-modules jlink plugin is disabled because (a) it is not
+ // useful on Android, and (b) it causes errors with later versions of jlink
+ // when the jdk.internal.module is absent from java.base (as it is here).
+ ` --disable-plugin system-modules && ` +
`cp ${config.JrtFsJar} ${outDir}/lib/`,
CommandDeps: []string{
"${moduleInfoJavaPath}",