Android NDK Native Methode nicht gefunden Fehler
Ich versuche, eine Android-Anwendung mit nativem Code zu erstellen, also möchte ich testen, ob ndk erfolgreich ausgeführt wird. Wenn ich versuche, mein erstes Hallo-Welt-Projektprotokoll auszuführen, sagt cat:
01-21 23:30:06.780: E/AndroidRuntime(939): FATAL EXCEPTION: main
01-21 23:30:06.780: E/AndroidRuntime(939): java.lang.UnsatisfiedLinkError:
Native method not found: com.example.ndktesting.MainActivity.invokeNativeFunction:()Ljava/lang/String;
Ich habe einige Stackoverflow-Antworten überprüft, konnte aber meine Antwort nicht finden. Hier ist mein Code für Java und C. Ich verwende die Android ndk r8d-Version.
//ndktest.c
#include <string.h>
#include <jni.h>
extern "C"
{
JNIEXPORT jstring JNICALL Java_com_example_ndktesting_ndktest_MainActivity_invokeNativeFunction(JNIEnv* env, jobject thiz)
};
JNIEXPORT jstring JNICALL Java_com_example_ndktesting_ndktest_MainActivity_invokeNativeFunction(JNIEnv* env, jobject thiz)
{
return (*env)->NewStringUTF(env, "Hello from native code!");
}
Hier ist mein MainActivity-Java-Code
package com.example.ndktesting;
public class MainActivity extends Activity
{
//declare the native code function - must match ndktest.c
private native String invokeNativeFunction();
public native String unimplementedinvokeNativeFunction();
// load the library - name matches jni/Android.mk
static
{
System.loadLibrary("ndktest");
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// this is where we call the native code
String hello = invokeNativeFunction();
new AlertDialog.Builder(this).setMessage(hello).show();
}
}
Android machen Dateicode:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_MODULE := ndktest
LOCAL_SRC_FILES := ndktest.c
include $(BUILD_SHARED_LIBRARY)