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

Unity导入含JNI文件的Android库(.aar)时遇UnsatisfiedLinkError错误

Hey there, I’ve dealt with this exact UnsatisfiedLinkError a few times when integrating Android AARs with native libraries into Unity—let’s break down what’s going on and fix it step by step:

Why This Happens

The error means Unity’s Android build can’t locate your libnative-lib.so file. Usually this is because the native library isn’t being placed in the right location during the build, there’s a mismatch in supported CPU architectures, or the library name isn’t exactly what the system expects.

Fixes to Try
  • Double-check your AAR’s native library structure
    Grab a zip tool and unpack your AAR. Look for a jni folder inside—there should be subfolders for each CPU architecture your library supports (like armeabi-v7a, arm64-v8a, x86, x86_64). Each of these folders must contain exactly libnative-lib.so. If any architecture you’re targeting is missing, that’s a problem.

  • Align Unity’s target architectures with your library
    Open Unity’s Player Settings (Edit > Project Settings > Player), go to the Android tab, and expand Other Settings > Configuration. Make sure the Target Architectures only includes the ones your libnative-lib.so supports. For example, if your library only works on 64-bit ARM devices, uncheck x86 and armeabi-v7a to avoid Unity trying to load a missing library for those architectures.

  • Manually copy native libraries to Unity’s Plugins folder
    Sometimes Unity doesn’t auto-extract native libraries from AARs. Here’s how to fix that:

    1. Unpack your AAR and pull out all the architecture folders from the jni directory.
    2. In your Unity project, create Assets/Plugins/Android/libs if it doesn’t exist.
    3. Paste the architecture folders (e.g., arm64-v8a) into this libs folder.
    4. Select each folder in Unity’s Project window, go to the Inspector, set Platform to Android, pick the matching CPU architecture, and check Include in Build.
  • Confirm the library name is exact (case-sensitive!)
    Android treats native library names as case-sensitive. The error says it’s looking for libnative-lib.so—make sure your AAR’s library has exactly that name (no typos, no capitalization differences like LibNative-Lib.so).

  • Check for conflicting libraries
    If your Unity project has other AARs or native libraries with the same libnative-lib.so name, they might be conflicting. Search your entire project for this file and remove duplicates or ensure all versions are identical.

  • Force Unity to recognize the AAR’s native libraries
    Create a .gradle file with the same name as your AAR in Assets/Plugins/Android (e.g., if your AAR is mylibrary.aar, make mylibrary.gradle). Add this code to it:

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.aar'])
    }
    android {
        sourceSets {
            main {
                jniLibs.srcDirs = ['libs']
            }
        }
    }
    

    This tells Unity’s build system explicitly where to find the native libraries in the AAR.

内容的提问来源于stack exchange,提问作者Saurabh Pandey

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:56:37