Android NDK C++ JNI (no implementation found for native…)

后端 未结 11 1146
慢半拍i
慢半拍i 2020-11-30 02:02

I\'m trying to use the NDK with C++ and can\'t seem to get the method naming convention correct. my native method is as follows:

extern \"C\" {
JNIEXPORT voi         


        
相关标签:
11条回答
  • 2020-11-30 02:49

    Called extern "C" as provided in the automatically-generated Studio example, but forgot to wrap the entire rest of the file, including following functions, in {} brackets. Only the first function worked.

    0 讨论(0)
  • 2020-11-30 02:51

    There are a couple of things that can lead to "no implementation found". One is getting the function prototype name wrong, another is failing to load the .so at all. Are you sure that System.loadLibrary() is being called before the method is used?

    If you don't have a JNI_OnLoad function defined, you may want to create one and have it spit out a log message just to verify that the lib is getting pulled in successfully.

    You already dodged the most common problem -- forgetting to use extern "C" -- so it's either the above or some slight misspelling. What does the Java declaration look like?

    0 讨论(0)
  • 2020-11-30 02:53

    I try all above solutions, but no one can solved my build error(jni java.lang.UnsatisfiedLinkError: No implementation found for...), at last I found that I forget to add my verify.cpp source file to CMakeList.txt add_library segement(verify.cpp is auto generate by Ctrl + Enter short key, maybe other file name), hope my response can help some one.

    my build environment: Gradle + CMake

    0 讨论(0)
  • 2020-11-30 02:57

    Use javah (part of Java SDK). Its the tool exactly for this (generates .h header from .class file).

    0 讨论(0)
  • 2020-11-30 02:57

    I faced the same problem twice. It happened, that the phone I tried to start the app from Android Studio used an API level that I haven't downloaded yet in Android Studio.

    1. Upgrade Android Studio to the latest version
    2. Download the necessary API from within Android Studio
    0 讨论(0)
提交回复
热议问题