kotlin-toolkit icon indicating copy to clipboard operation
kotlin-toolkit copied to clipboard

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

Open mickael-menu opened this issue 5 years ago • 15 comments

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 avatar May 18 '20 07:05 mickael-menu

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

mickael-menu avatar Jan 13 '21 11:01 mickael-menu

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 avatar Jan 13 '21 11:01 danielweck

See Slack discussion for further analysis of the LCP build issue

danielweck avatar Jan 13 '21 11:01 danielweck

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

mickael-menu avatar Jan 13 '21 11:01 mickael-menu

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

danielweck avatar Jan 13 '21 11:01 danielweck

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

danielweck avatar Jan 13 '21 11:01 danielweck

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)

danielweck avatar Jan 13 '21 11:01 danielweck

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

cursem avatar Apr 23 '21 08:04 cursem

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

mickael-menu avatar Apr 23 '21 08:04 mickael-menu

@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.

cursem avatar Jul 13 '21 04:07 cursem

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 avatar Oct 07 '21 08:10 mickael-menu

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
}

mickael-menu avatar Nov 03 '21 12:11 mickael-menu

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

aferditamuriqi avatar Nov 03 '21 12:11 aferditamuriqi

Good to know, thanks!

mickael-menu avatar Nov 03 '21 12:11 mickael-menu

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.

stevenzeck avatar Nov 05 '22 21:11 stevenzeck