You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何外部添加.so文件?解决java.lang.UnsatisfiedLinkError找不到库异常

Fixing java.lang.UnsatisfiedLinkError by Adding External .so Files

Hey, let's work through this UnsatisfiedLinkError you're hitting. The error log clearly states it can't locate liblibAndroidImageFilter.so.so—first, notice that double .so suffix might be a typo in your code or filename, but let's walk through the step-by-step process to properly add external .so files to your Android project.

Step 1: Verify .so File Architecture Compatibility

Your device is running on an arm64-v8a architecture (seen in the log: /data/app/.../lib/arm64). Make sure you have .so files built for all the architectures you want to support (common ones: arm64-v8a, armeabi-v7a, x86, x86_64). Don't just include one architecture unless you explicitly restrict your app to it.

Step 2: Create the jniLibs Directory in Your Project

Android Studio looks for native libraries in the jniLibs directory by default. Here's how to set it up:

  • Navigate to app/src/main in your project.
  • If the jniLibs folder doesn't exist, create it.
  • Inside jniLibs, create subdirectories named after each architecture you support (e.g., arm64-v8a, armeabi-v7a).
  • Place your corresponding .so files into the matching architecture subdirectories.

Important: Double-check the filename! The error is looking for liblibAndroidImageFilter.so.so—ensure your file matches this name, or fix the code that loads the library (more on that in Step 4).

Step 3: Configure Your Module's build.gradle

Make sure your Gradle build file recognizes the jniLibs directory and properly packages the native libraries. Add this to your module-level build.gradle (under the android block):

android {
    // ... other configurations

    sourceSets {
        main {
            jniLibs.srcDirs = ['src/main/jniLibs']
            // If you placed .so files in the "libs" folder instead, use:
            // jniLibs.srcDirs = ['libs']
        }
    }

    // Optional: Restrict to specific architectures to reduce APK size
    defaultConfig {
        // ... other configurations
        ndk {
            abiFilters 'arm64-v8a', 'armeabi-v7a'
        }
    }
}

Step 4: Fix the Library Loading Code

Looking at the stack trace, the library is loaded in LightFilter.java's static initializer with System.loadLibrary(). Remember:

  • The argument to System.loadLibrary() should be the name of the library without the lib prefix and .so suffix.
  • The error shows it's searching for liblibAndroidImageFilter.so.so—this means your code probably has something like System.loadLibrary("libAndroidImageFilter.so") (extra .so suffix). Correct it to:
    // If your .so file is named liblibAndroidImageFilter.so
    System.loadLibrary("libAndroidImageFilter");
    // Or if the file should be libAndroidImageFilter.so (more likely, fixing the typo)
    System.loadLibrary("AndroidImageFilter");
    
    Match this to your actual .so filename to avoid the double .so issue.

Step 5: Clean and Rebuild Your Project

Cached build files can cause unexpected issues. Do the following:

  1. Go to Build > Clean Project in Android Studio.
  2. Then go to Build > Rebuild Project.
  3. Run your app again.

Step 6: Verify the APK Includes the .so File

To confirm the library is properly packaged:

  1. Locate your generated APK (usually in app/build/outputs/apk/debug/).
  2. Unzip the APK and check the lib/[architecture]/ directory (e.g., lib/arm64-v8a/).
  3. Ensure your .so file is present there.

Common Pitfalls to Watch For

  • File Permissions: Make sure your .so files have read permissions (most files copied from valid sources will already have this, but it's worth checking).
  • SDK Compatibility: Ensure the .so files were compiled against an SDK version that's compatible with your app's minSdkVersion.
  • Android App Bundle: If you're using App Bundles, test with a full APK first—Bundles deliver architecture-specific libraries on demand, which can cause issues during local testing.

内容的提问来源于stack exchange,提问作者ishan gengadiya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:21:46