Android Studio中.so文件管理及libopencv_java.so找不到问题求助
Hey there, let's work through this UnsatisfiedLinkError issue with libopencv_java.so—I’ve dealt with this exact problem a few times, so here are the step-by-step fixes that should resolve it:
First, make sure your jniLibs is in the right place and organized correctly. Android Studio expects it under src/main/, and you need subdirectories for each supported ABI (like armeabi-v7a, arm64-v8a, x86). Each ABI folder must contain the corresponding libopencv_java.so file. Your structure should look like this:
src/ └── main/ └── jniLibs/ ├── armeabi-v7a/ │ └── libopencv_java.so ├── arm64-v8a/ │ └── libopencv_java.so └── x86/ └── libopencv_java.so
Double-check the filename too—typos or wrong case (like LibOpenCV_Java.so) will break things.
Open your app module’s build.gradle file and confirm these settings:
- Ensure Gradle recognizes your jniLibs location. Add this inside the
androidblock if it’s missing:sourceSets { main { jniLibs.srcDirs = ['src/main/jniLibs'] // If you stored .so files in the libs folder instead, use ['src/main/libs'] } } - Check if you’ve restricted ABIs accidentally. If your
defaultConfighasabiFiltersset to a subset that doesn’t match your .so files, the library won’t be found. Either update the filters to match your supported ABIs or remove the line entirely:defaultConfig { ... ndk { abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' } }
Cached build files often cause weird missing-library errors. Do this:
- Click
Build > Clean Projectin Android Studio - Then click
Build > Rebuild Project - For extra measure, you can manually delete the
buildfolder in your app module and re-run the build.
Make sure the libopencv_java.so file matches the OpenCV version your code depends on. If you’re using OpenCV 4.x in your project, don’t use a .so file from OpenCV 3.x—version mismatches will trigger this error every time.
Unzip your generated APK (you can rename it to .zip and extract) and check the lib/ directory. You should see your ABI folders with libopencv_java.so inside each one. If it’s missing, go back to steps 1 and 2 to fix your directory or Gradle config.
Double-check your static block where you load the library—you don’t need the lib prefix or .so suffix. It should look like this:
static { try { System.loadLibrary("opencv_java"); } catch (UnsatisfiedLinkError e) { Log.e("OpenCV", "Failed to load library: " + e.getMessage()); } }
Avoid adding extra parts to the library name here—that’s a common mistake.
内容的提问来源于stack exchange,提问作者alter

