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

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 void JNICALL Java_com_test_jnitest_SurfaceRenderer_drawFromJni
(JNIEnv* env, jclass c)

with a header wrapped in extern "C" {} aslo.

Everything compiles fine, creates a .so file and copies to the libs folder under my project, but when I debug and run in Eclipse I keep getting a log cat message that of "no implementation found for native...". Is there something i'm missing as all the NDK examples are in C?


Asked by: Anna539 | Posted: 24-01-2022

Answer 1

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?

Answered by: Connie111 | Posted: 25-02-2022

Answer 2

An additional cause for this error: your undecorated native method name must not contain an underscore!

For example, I wanted to export a C function named AudioCapture_Ping(). Here is my export declaration in C:

JNI_EXPORT int Java_com_obsidian_mobilehashhost_MainActivity_AudioCapture_Ping(JNIEnv *pJniEnv, jobject object);  //Notice the underscore before Ping

Here was my Java class importing the function:

package com.obsidian.mobileaudiohashhost;
public class MainActivity extends Activity {
    private native int AudioCapture_Ping();  // FAILS

I could not get Android to dynamically link to my native method until I removed the underscore:

JNI_EXPORT int Java_com_obsidian_mobilehashhost_MainActivity_AudioCapturePing(JNIEnv *pJniEnv, jobject object); 

package com.obsidian.mobileaudiohashhost;
public class MainActivity extends Activity {
    private native int AudioCapturePing();  // THIS WORKS!

Answered by: Julian238 | Posted: 25-02-2022

Answer 3

I had the same problem, but to me the error was in the file I had it:


but should have this:


note the detail += instead :=

I hope that helps.

Answered by: Clark643 | Posted: 25-02-2022

Answer 4

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.

Answered by: Lana413 | Posted: 25-02-2022

Answer 5

An additional reason: Use LOCAL_WHOLE_STATIC_LIBRARIES instead of LOCAL_STATIC_LIBRARIES in This stops the library from optimizing out unused API calls because the NDK cannot detect the use of the native bindings from java code.

Answered by: Kellan937 | Posted: 25-02-2022

Answer 6

There is a cpp example under apps in ndk:

Answered by: Justin557 | Posted: 25-02-2022

Answer 7

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

Answered by: Miller608 | Posted: 25-02-2022

Answer 8

If your package name includes _ character, you should write 1(one) after _ character as shown below:

package com.example.testcpp_2;



Answered by: Lucas267 | Posted: 25-02-2022

Answer 9

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

Answered by: Sophia282 | Posted: 25-02-2022

Answer 10

I Faced the same problem, and in my case the reason was that I had underscore in package name "RFID_Test" I renamed the Package and it worked. Thanks user1222021

Answered by: Caroline787 | Posted: 25-02-2022

Answer 11

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

Answered by: Walter131 | Posted: 25-02-2022

Similar questions

Android libc version and malloc implementation

What libc implementation is used in Android platform? What malloc implementation is used (ptmalloc or tcmalloc or anything other)?

IP Camera implementation in Android(View live video from IP Camera)

I have a requirement to implement IP camera's for my client's Organization(May be 5 or more). I need to provide facility to view these camera's preview in their Android mobiles. I found an application already available in Android Market(IP Cam Viewer) and it is what exactly my Client asking. Can anyone suggest me the best IP camera(It should be operated by their mobile i.e moving it up and down, as well as left an...

What is likely cause of Android runtime exception "No suitable Log implementation" related to logging in 3rd-party jar?

I am creating an Android app that includes a third party jar. That third party jar utilizes internal logging that is failing to initialize when I run the app, with this error: "org.apache.commons.logging.LogConfigurationException: No suitable Log implementation". The 3rd party jar appears to be using org.apache.commons.logging and to depend on log4j, specifically log4j-1.2.14.jar. I have packaged the log4j ja...

java - Duplicate case error during implementation of two dialogs

I am trying to implement both the date picker and time picker. However, when I try to define two cases in the following code, I get an error that there is a duplicate case. Code: @Override protected Dialog onCreateDialog(int id) { switch(id){ case ID_DATEPICKER: Toast.makeText(SendMail.this, "Select Appointment Date", Toast.LENGTH_L...

service - android: implementation and make listener to a socket

i'm devlopping an application for android, i need to make a session between client(cell phone) and e web server (apache) and keep alive this session to receive notification from the server for this i may implement socket also make a listener for this socket to notify the client if a file is ready to download, after receiving this notifcation (the ID of the file) the client will download this file so my que...

java - Transparently storing class state without exposing implementation

I have a model (MVC) class whose internal state (which basically contains of private int fields) I want to store. The program is running on Android (for now) so I need to store the in a Bundle, but I'll be using the same class later in a desktop application where I'll have to store the state some other way, so I can't reference Bundle directly in my class. So my quest...

android - A simple free MIDI implementation in Java besides javax.sound.midi: Are there any?

The problem is: Android doesn't implement javax.sound.midi. I need a simple free library that allows me to create simple 1-track midi files. I searched the net for it, but can't really find anything, since everything uses javax.sound.midi . The license needs to be one where I don't need to opensource my linked app. Any ideas? I also looked into the fileformat itself. However, I...

mobile - Android Login - Best implementation

I'm planning to implement an Android application that requires a login screen. If the user opens the activity something like this should happen: If user is logged in, goto 3 If user is not logged in open the login screen and perfom login Show my application content So, what's the "correct" way of implementing a login? Implement a StartActivity

java - Android game thread lifecycle implementation

So I am working on a new basic 2d game for Android and was setting up my usual implementation of a game thread working with a SurfaceView. While typing away, I realized that, while this seems to work, I would really like to know if there is a better way to achieve the same results. Here are the basics of what I do right now (I apologize for the verbosity, I'm trying to compress as much as possible): GameActivity cl...

Is there SASL implementation that works on Android?

Android has no SASL by default. Curious, if there some 3rd party implementation that can be used on Android? Did some one try

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android