我正在android ndk中尝试简单的加法程序。但我得到以下异常 -
java.lang.exceptionininitializererror
Java文件-
public class MainActivity extends Activity {
private native void MyMethod(int a,int b);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyMethod(4,5);
}
static {
System.loadLibrary("native"); // here i'm getting exception
}
}
安卓.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := native
LOCAL_SRC_FILES := native.c
include $(BUILD_STATIC_LIBRARY)
本机.c
#include <jni.h>
#include <string.h>
#include <android/log.h>
#define DEBUG_TAG "NDKSetupActivity"
void Java_com_example_additionndk_MainActivity_MyMethod(JNIEnv * env, jobject this, jint a,jint b)
{
jint c=a+b;
__android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "addition: %d", c);
}