# java.lang.UnsatisfiedLinkError: 未找到 java.lang.String com.example.MyClass.nativeGetString() 的实现（尝试了 Java_com_example_MyClass_nativeGetString 和 Java_com_example_MyClass_nativeGetString__）

- **ID:** `android/ndk-jni-method-not-found`
- **领域:** android
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

JNI 本地方法签名不匹配：C/C++ 函数名与 Java 期望的修饰名不匹配，或本地库未正确加载。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| NDK r23 - r26 | active | — | — |
| CMake 3.22 - 3.28 | active | — | — |
| Android Gradle Plugin 7.0 - 8.2 | active | — | — |

## 解决方案

1. ```
   Verify the JNI method name by running 'javac -h . MyClass.java' to generate the correct header, then update the C/C++ function signature accordingly. Example: 'JNIEXPORT jstring JNICALL Java_com_example_MyClass_nativeGetString(JNIEnv *env, jobject thiz)'
   ```
2. ```
   Ensure the native library is loaded in a static block: 'static { System.loadLibrary("mylib"); }' and check that the library name matches the .so file (e.g., libmylib.so).
   ```

## 无效尝试

- **** — If the library is compiled only for arm64-v8a but the device is armeabi-v7a, the native method won't be found; the ABI must match. (50% 失败率)
- **** — The JNI naming convention requires exact match; any renaming breaks the linkage. (50% 失败率)
