I'm working on an Android project with a pre-compiled .so
file for OpenCV. The original distribution I used as my base (courtesy of QuickBird Studios) contains 2 .so
files: libopencv_java4
and libc++_shared
. The two .so
files are taken from a .aar
library which I had to unpack in order to address a known, long-standing issue in the OpenCV Android implementation. These two SOs are stored in the same folder in my project tree, as seen here. The other ABIs share identical structure to arm64-v8a
.
When compiling the APK with Intellij IDEA (v2022.1.3), the APK analyzer shows that both .so
files have been packaged in to lib/{ABI}
, as can be seen here (in this case, the ABI is arm64-v8a
). So far, so good.
However, when I go to load the OpenCV library (which calls upon libc++_shared
), I receive the following error:
W/System.err: java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found: needed by {omitted}/base.apk/lib/arm64-v8a/libopencv_java4.so in namespace classloader-namespace
I've attempted building the APK without including libstdc++_shared
, under the pretense that Gradle claims to be able to include the C++ shared libraries automatically. This failed with the same error message as above, with no libc++_shared.so
in the APK.
I've also attempted to create a dummy native C++ file, in order to get libc++_shared
added via CMake during the Gradle build process. This also failed with the above error. I did not think to check the APK during this attempt.
In a previous iteration of this project (before I discovered the bug in the OpenCV Android implementation), I was able to compile and run without issue by including the .aar
file as an external library.
Between each of the above attempts, I've performed a full Gradle cache invalidation to make sure I'm not keeping broken files from previous tries.
I'm completely flummoxed. Did I break something when I unpacked the .aar
to fix the bug? How can I get Android to acknowledge what's inside the APK?
I had the same issue after upgrading the Gradle plugin. the nonsense disappear after I also upgrade the Gradle build tool.
dependencies {
//after upgrad from 3.5.1 the link error disappear
classpath "com.android.tools.build:gradle:3.5.4"
...
}