Downgrade to Java 17 and remove Java 21 features for Android compatibility#1513
Open
aslan564 wants to merge 1 commit intoLibrePDF:masterfrom
Open
Downgrade to Java 17 and remove Java 21 features for Android compatibility#1513aslan564 wants to merge 1 commit intoLibrePDF:masterfrom
aslan564 wants to merge 1 commit intoLibrePDF:masterfrom
Conversation
…ility
Java Records, Virtual Threads, and SequencedCollection methods cause
Android D8 desugaring failures ("Global synthetics are not supported
with D8"). This commit ensures OpenPDF works on Android by:
- Lowering Java source/target from 21 to 17 in pom.xml
- Replacing all 28 Java Records across 15 files with regular final
classes (public final fields + accessor methods for backward compat)
- Replacing Virtual Threads (Executors.newVirtualThreadPerTaskExecutor)
with CachedThreadPool in PdfBatch.java
- Replacing SequencedCollection methods (getFirst/getLast) with
standard List access (get(0)/get(size()-1))
- Updating tests to remove Virtual Thread assertions
All 2264 tests pass. Bytecode verification confirms zero
java.lang.Record references remain.
Fixes LibrePDF#1512
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Contributor
|
If you need to use OpenPDF on Java 17, you can use the OpenPDF 2.0.5 release. The 2.0 branch supports Java 17. Java on Android is it's very unique special creation. Maybe a fork of OpenPDF which is specific for Android would be a good idea. Yes, I suggest someone creates a fork of OpenPDF for Android. So I suggest OpenPDF will focus on the main modern Java version, for which Java 21 is a good choice in 2026. There has been a significant effort to modernize OpenPDF 3.x for Java 21, so this PR you propose will halt the modernization. https://github.com/LibrePDF/OpenPDF/releases/tag/2.0.5 <dependency>
<groupId>com.github.librepdf</groupId>
<artifactId>openpdf</artifactId>
<version>2.0.5</version>
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
pom.xmlfinalclasses (withpublic finalfields + accessor methods for backward compatibility)Executors.newVirtualThreadPerTaskExecutor) withCachedThreadPoolinPdfBatch.javaSequencedCollectionmethods (getFirst()/getLast()) with standardListaccess (get(0)/get(size()-1))Motivation
Java Records, Virtual Threads, and SequencedCollection methods cause Android D8 desugaring failures:
Android's D8 compiler cannot handle
java.lang.Recordbytecode without explicit AGP 8.3+global-syntheticsconfiguration. This breaks all Android projects that depend on OpenPDF (directly or transitively), even if they only use a small subset of OpenPDF features.By downgrading to Java 17 and replacing these Java 21 features, OpenPDF becomes fully compatible with Android development toolchains.
Test plan
mvn clean verify)java.lang.Recordreferences remainFixes #1512