build(android): link libdocument_detector against shared libc++ - #726
Merged
Merged
Conversation
The napi runtime (@nativescript/android-quickjs-ng) already ships libc++_shared.so for every ABI, so the static STL inside libdocument_detector.so was a duplicate. Switch ANDROID_STL to c++_shared. Stripped .so per ABI: arm64-v8a 7132720 -> 6695728 (-427 KB) armeabi-v7a 4503864 -> 4247608 (-250 KB) x86 8374820 -> 7955876 (-409 KB) x86_64 9591536 -> 9174512 (-407 KB) The existing pickFirst rules in App_Resources/*/Android/app.gradle keep a single copy in the APK. Also align src-native ndkVersion with the one the real build uses. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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
libdocument_detector.sowas built with-DANDROID_STL=c++_static, so each ABI carried a private copy of libc++/libc++abi. The napi runtime (@nativescript/android-quickjs-ng) already shipslibc++_shared.sofor all 4 ABIs, so that copy was pure duplication.-DANDROID_STL=c++_shared. The existingpickFirst 'lib/*/libc++_shared.so'rules inApp_Resources/*/Android/app.gradlekeep exactly one copy in the APK — verified, APK still has a singlelibc++_shared.so(the runtime's).src-native/.../build.gradlendkVersionwith the one the real build actually uses (27.3.13750724, frombefore-plugins.gradle).Stripped
libdocument_detector.so, before -> after:Bulk of it is
locale.cpp.o(145 KB) andcxa_demangle.cpp.o(113 KB).ABI compatibility
The runtime's
libc++_shared.sois NDK r28 (clang 21); the plugin builds with NDK 27.3 (clang 18). Both use thestd::__ndk1inline namespace, as do the prebuiltlibopencv_*.a/libtesseract.a/libleptonica.a. Only 12 symbols differ between the two shared libs (allstd::pmr/ GC-declare) and none are referenced bylibdocument_detector.so. After the switch the.sohas zero unresolved non-libc symbols; all 170 libc++ imports are exported by the runtime's copy.libNativeScript.so's own 113 libc++ imports resolve against either copy, sopickFirstis safe whichever wins.Testing
Built and installed the arm64 debug APK on an emulator:
libdocument_detector.sonow listsNEEDED libc++_shared.soon all 4 ABIsnativeloader: Load ... libdocument_detector.so ... : ok— nodlopen/symbol errorsStill needs a check on a real arm64 device: the emulator run crashes in
kleidicv::sve2::remap_s16point5(SIGILL) during crop, which is the pre-existing Apple-Silicon-emulator SVE issue documented incpp/CMakeLists.txt(DISABLE_SVE), not related to this change — with-PdisableSVEthe crop path gets past it. OCR (tesseract), QR scan (cardwallet flavour,-PwithQRCode) and PDF export have not been exercised end-to-end yet.