Search code examples
androidandroid-ndkandroid-ndk-r5

Android NDK: No rule to make target all and native method not found


I am using android NDK to use one c++ library in my application. When I run my application, I always got a error message which is java.lang.UnsatisfiedLinkError: Native method not found. I checked my code many times but I did not find anything. Moreover I got another error message which is No rule to make target all.

LOCAL_C_INCLUDES += ${NDKROOT}/sources/cxx-stl/stlport/stlport

LOCAL_PATH := $(call my-dir)

LOCAL_ALLOW_UNDEFINED_SYMBOLS = true
include $(CLEAR_VARS)
LOCAL_MODULE := my-module-jni
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*/*.cpp)
include $(BUILD_SHARED_LIBRARY)

extern "C" {
JNIEXPORT jstring JNICALL
Java_com_test_ndk_MyClassName_test
(JNIEnv *env, jobject obj)
{
    return env->NewStringUTF("Hello from C++ over JNI!");
}
    }
    public class MyClassName extends Activity{
    public static native String test();
    ......
    }

In my jni folder I have many c++ classes and folders. I think problem is my android.mk file. What should I change in my android.mk file?


Solution

  • Given that you mention in the comments that your code works in a smaller test application but not a larger application make sure the larger application is actually loading the library in the Java Activity like so:

    // Load the .so
    static {
        System.loadLibrary("libmy-jni-module");
    }