android native方法找不到,Android NDK Native方法找不到错误

我正在尝试使用本机代码构建

Android应用程序,所以我想测试ndk是否成功运行.当我尝试运行我的第一个hello world项目

日志猫说,

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;

我检查了一些stackoverflow答案,但找不到我的答案.这是我的代码为java和c.I我正在使用android ndk r8d版本.

//ndktest.c

#include

#include

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!");

}

这是我的MainActivity java代码

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制作文件代码:

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值