readium / kotlin-toolkit

A toolkit for ebooks, audiobooks and comics written in Kotlin
https://readium.org/kotlin-toolkit
BSD 3-Clause "New" or "Revised" License
180 stars 77 forks source link

Conflict on libc++_shared.so between liblcp and PDFiumAndroid #29

Open mickael-menu opened 4 years ago

mickael-menu commented 4 years ago

It looks like there's a conflict between the latest version of PDFiumAndroid 1.9.0 and liblcp. When building, I get this error:

More than one file was found with OS independent path "lib/arm64-v8a/libc++_shared.so"

I managed to build by adding these settings in the build.gradle of the app:

packagingOptions {
    pickFirst 'lib/x86/libc++_shared.so'
    pickFirst 'lib/x86_64/libc++_shared.so'
    pickFirst 'lib/arm64-v8a/libc++_shared.so'
    pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}

But then, the LCP lib crashes with this error:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__sfp_handle_exceptions" referenced by "/data/app/org.readium.reader-9khTthf02oLgGERC1SDuCQ==/lib/arm64/liblcp.so"...
        at java.lang.Runtime.loadLibrary0(Runtime.java:1071)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
        at java.lang.System.loadLibrary(System.java:1667)
        at org.readium.lcp.sdk.Lcp.<clinit>(Lcp.kt:32)
        at org.readium.r2.lcp.license.LicenseValidation$isProduction$1.invoke(LicenseValidation.kt:118)

However, it works with an older version of PDFiumAndroid, so now we're stuck with PDFiumAndroid 1.6.1 (instead of 1.9.0) and AndroidPdfViewer 2.8.2 (instead of 3.2.0).

Any help is most welcome.

mickael-menu commented 3 years ago

@danielweck Do you have any idea if there's something that could be done on the liblcp side to address this problem? Thanks

danielweck commented 3 years ago

I think, more likely something @aferditamuriqi can help with, because Android. I am only familiar with the NodeJS and plain UNIX LCP native lib builds.

danielweck commented 3 years ago

See Slack discussion for further analysis of the LCP build issue

mickael-menu commented 3 years ago

According to @danielweck , this pull request could address a similar issue: https://github.com/readium/readium-lcp-client/pull/49

Gradle tweaks to “pick” native lib dependency … but cannot remember the exact pattern

danielweck commented 3 years ago

I think you meant https://github.com/readium/SDKLauncher-Android/pull/152/files

danielweck commented 3 years ago

Alternatively, maybe some inspiration in this PR, but I doubt so https://github.com/readium/SDKLauncher-Android/pull/147/files

danielweck commented 3 years ago

it’s been a long time since I rewrote the Gradles to integrate ReadiumSDK and ReadiumLCP (Readium1) for Android build matrix ARM/x86 32/64 release/debug … I do not remember all the techniques in the PR (…I imagine the Gradle / NDK syntax evolved since then)

cursem commented 3 years ago

@mickael-menu Hi, Have you solved this problem?

mickael-menu commented 3 years ago

@cursem No, I didn't spend more time on this. Let us know if you tackle this.

cursem commented 3 years ago

@cursem No, I didn't spend more time on this. Let us know if you tackle this.

You should make sure compile liblcp and PDFiumAndroid with the same ndk version.

mickael-menu commented 2 years ago

I tried again upgrading AndroidPdfViewer and liblcp doesn't seem to crash anymore, after adding the following in the build.gradle:

packagingOptions {
    pickFirst 'lib/x86/libc++_shared.so'
    pickFirst 'lib/x86_64/libc++_shared.so'
    pickFirst 'lib/arm64-v8a/libc++_shared.so'
    pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}

It could have been fixed after upgrading to Gradle 7, but will need more testing to make sure there's no issue on older Android versions.

mickael-menu commented 2 years ago

So bad news, the above fix failed with a different build of liblcp (another app).

I found an alternative though, which is to force the downgrade of pdfium-android. This doesn't seem to cause any issue with AndroidPdfViewer and doesn't conflict anymore with liblcp.

implementation("com.github.barteksc:pdfium-android:1.8.2") {
    force = true
}
aferditamuriqi commented 2 years ago

@mickael-menu i'll be looking into the lcp libs, it's probably time to upgrade them. Will discuss with @llemeurfr

mickael-menu commented 2 years ago

Good to know, thanks!

stevenzeck commented 1 year ago

Another repository that is being maintained (for now, fingers crossed) is https://github.com/mhiew/PdfiumAndroid and https://github.com/mhiew/AndroidPdfViewer. I tried their latest versions (PDFium 1.9.2 and AndroidPdfViewer 3.2.0-beta.3) in the toolkit here along with LCP and it worked. I did have to add jniLibs.pickFirsts.add though, which isn't good.

Per @cursem it sounds like liblcp and PDFium need to be compiled using the same NDK version to avoid the 2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs error? Not even sure where to find the NDK version that is used. Trying to find the conversation in Slack but not having any luck.