Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android ResourceShrinker fails with IllegalAccessError on JDK 17 #297

Open
lukaciko opened this issue Mar 22, 2024 · 0 comments
Open

Android ResourceShrinker fails with IllegalAccessError on JDK 17 #297

lukaciko opened this issue Mar 22, 2024 · 0 comments

Comments

@lukaciko
Copy link
Contributor

Description of the bug:

When switching our Android builds from JDK 11 to JDK 17, we get the following error when building android_binary targets with resource shrinking enabled:

ERROR: /Users/spotify-buildagent/buildAgent/work/dci-wd/android/client-android/src/main/java/com/spotify/app/music/app/BUILD.bazel:41:12: Shrinking resources for //src/main/java/com/spotify/app/music/app:app failed: (Exit 1): ResourceProcessorBusyBox failed: error executing ResourceShrinker command (from target //src/main/java/com/spotify/app/music/app:app)
ate/var/tmp/_bazel_spotify-buildagent/985b781559c7830232d18af8d0be54d9/sandbox/darwin-sandbox/51832/execroot/client_android && \
  exec env - \
    BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN='' \
    PATH=/bin:/usr/bin:/usr/local/bin \
  bazel-out/darwin_arm64-opt-exec-ST-13d3ddad9198/bin/external/bazel_tools/src/tools/android/java/com/google/devtools/build/android/ResourceProcessorBusyBox @bazel-out/darwin_arm64-opt/bin/src/main/java/com/spotify/app/music/app/app_shrunk.ap_-0.params)
# Configuration: 90658d1367aa8bc9900aca7af82ba46f945ae0750452ba93c59ddba269cacbf4
# Execution platform: @@local_config_platform//:host
   
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
Exception in thread "main" java.lang.IllegalAccessError: superclass access check failed: class com.google.devtools.build.android.aapt2.ProtoResourceUsageAnalyzer$1 (in unnamed module @0x300ffa5d) cannot access class com.sun.org.apache.xerces.internal.dom.AttrImpl (in module java.xml) because module java.xml does not export com.sun.org.apache.xerces.internal.dom to unnamed module @0x300ffa5d
  at java.base/java.lang.ClassLoader.defineClass1(Native Method)
  at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
  at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
  at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
  at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
  at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
  at com.google.devtools.build.android.aapt2.ProtoResourceUsageAnalyzer.createSimpleAttr(ProtoResourceUsageAnalyzer.java:381)
  at com.google.devtools.build.android.aapt2.ProtoResourceUsageAnalyzer.lambda$shrink$4(ProtoResourceUsageAnalyzer.java:152)
  at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
  at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
  at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
  at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
  at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
  at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
  at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
  at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
  at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
  at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
  at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
  at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
  at com.google.devtools.build.android.aapt2.ProtoResourceUsageAnalyzer.shrink(ProtoResourceUsageAnalyzer.java:153)
  at com.google.devtools.build.android.ResourcesZip.shrinkUsingProto(ResourcesZip.java:237)
  at com.google.devtools.build.android.Aapt2ResourceShrinkingAction.main(Aapt2ResourceShrinkingAction.java:78)
  at com.google.devtools.build.android.ResourceProcessorBusyBox$Tool$9.call(ResourceProcessorBusyBox.java:118)
  at com.google.devtools.build.android.ResourceProcessorBusyBox.processRequest(ResourceProcessorBusyBox.java:237)
  at com.google.devtools.build.android.ResourceProcessorBusyBox.main(ResourceProcessorBusyBox.java:184)

The issue can be fixed by adding

--add-exports=java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED"

to jvm_flags of ResourceProcessorBusyBox in src/tools/android/java/com/google/devtools/build/android/BUILD.tools.

Which category does this issue belong to?

Android

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

In short, build an android_binary with shrink_resources set to 1 and java_runtime_version / --tool_java_runtime_version set to 17. I can provide an example if needed.

Which operating system are you running Bazel on?

MacOS 13.6.4

What is the output of bazel info release?

release 7.0.2-24a18ed

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

We have a custom built version of the Bazel binary with close to 20 patches on top of 7.0.2, most of which are related to Android builds.

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants