bblanchon / pdfium-binaries

📰 Binary distribution of PDFium
789 stars 166 forks source link

Add support for Android API 21+ #161

Closed varahash closed 1 month ago

varahash commented 1 month ago

To make it work on Android 21+, we need following changes:

1) Change default_min_sdk_version, by default pdfium uses 26 for this variable, but we can set it to 21. This is actually lowest supported sdk version by pdfuim controlled by min_supported_sdk_version (see pdfium/build/config/android/config.gni:90)

2) Change library soname to avoid conflict with system pdfium library. Due to the linker bug on older Android API levels (which was fixed in API 23+ Correct soname/path handling (Available in API level >= 23) System linker prefers already loaded /system/lib/libpdfium.so library instead of our library when making symbol resolution. That why you can receive such errors https://github.com/bblanchon/pdfium-binaries/issues/147#issuecomment-1837542975

    For Android 21-22 i received error "UnsatisfiedLinkError: dlopen failed: cannot locate symbol "FPDFBookmark_GetFirstChild" referenced"
To mitigate this problem we need to change library `soname`, by changing `output_extension` variable to `cr.so` for example (it will produce `libpdfium.cr.so`), this variable then used in  [pdfium/build/toolchain/gcc_toolchain.gni:448](https://gn.googlesource.com/gn/+/e375226345b2be2bfc8c4549702ee3e437b5c136/build/toolchain/gcc_toolchain.gni?pli=1#458) to set `soname`.

Fixes #147

bblanchon commented 1 month ago

Hi @varahash,

Thank you for this contribution.

I don't plan on maintaining products beyond their end-of-life period, but I'm happy to change the target version if that is all we need. Please confirm that you tested the resulting build on old and recent versions of Android.

About the name change, it is a completely different issue and needs to be discussed elsewhere. Please create a dedicated PR for the rename.

Best regards, Benoit

varahash commented 1 month ago

Hi @bblanchon, thank you for reviewing this!

Yes, I can confirm this fix works for all Android versions, starting from Android 5 (API 21) to the latest one Android 14 (API 34).

I don't plan on maintaining products beyond their end-of-life period

The major libraries from Google still support API 21 level, it would awesome if could to do same (it actually does not require any hard work, just couple configuration changes)

About the name change, it is a completely different issue and needs to be discussed elsewhere

This change is essential to make it work on Android 5.x (API 21-22) (see details in PR description).

Or if you really against supporting of API 21-22 out-of-box, then maybe we can add option to build.sh, so that user can at least easily change library name if needed.