Android的NDK。未找到本地LCOM实施 [英] Android NDK. No implementation found for native Lcom
问题描述
所有我已经成功地prepare经过我的NDK日食(至少我这样认为),它不位于c code争辩了,但现在我得到没有找到实现本机LCOM每当我执行任何本地code ..它发生在NDK的样本太..
After all I've managed to "prepare" my eclipse for NDK (atleast i think so), it doesnt argue at c code anymore, but now I'm getting "No implementation found for native Lcom" anytime i execute any native code.. It happens on NDK's samples too..
我的.java
...
private native float pi();
static
{
System.loadLibrary("shit");
}
...
System.out.println(pi());
...
我的.cpp
My .cpp
#include <jni.h>
jfloat Java_com_example_shit_MainActivity_pi(JNIEnv * env, jobject obj) {
return 3.1415;
}
我的.mk
My .mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := shit
LOCAL_SRC_FILES := shit.cpp
include $(BUILD_SHARED_LIBRARY)
我的错误日志
My error log
11-14 18:30:16.231: D/dalvikvm(1739): Trying to load lib /data/data/com.example.shit/lib/libshit.so 0x413b1fc8
11-14 18:30:16.241: D/dalvikvm(1739): Added shared lib /data/data/com.example.shit/lib/libshit.so 0x413b1fc8
11-14 18:30:16.241: D/dalvikvm(1739): No JNI_OnLoad found in /data/data/com.example.shit/lib/libshit.so 0x413b1fc8, skipping init
11-14 18:30:16.271: D/TextLayoutCache(1739): Using debug level: 0 - Debug Enabled: 0
11-14 18:30:17.913: W/dalvikvm(1739): No implementation found for native Lcom/example/shit/MainActivity;.pi ()F
11-14 18:30:17.913: D/AndroidRuntime(1739): Shutting down VM
11-14 18:30:17.913: W/dalvikvm(1739): threadid=1: thread exiting with uncaught exception (group=0x40ab1210)
11-14 18:30:17.923: E/AndroidRuntime(1739): FATAL EXCEPTION: main
11-14 18:30:17.923: E/AndroidRuntime(1739): java.lang.IllegalStateException: Could not execute method of the activity
...
11-14 18:30:17.923: E/AndroidRuntime(1739): at dalvik.system.NativeStart.main(Native Method)
...
11-14 18:30:17.923: E/AndroidRuntime(1739): Caused by: java.lang.UnsatisfiedLinkError: pi
11-14 18:30:17.923: E/AndroidRuntime(1739): at com.example.shit.MainActivity.pi(Native Method)
11-14 18:30:17.923: E/AndroidRuntime(1739): at com.example.shit.MainActivity.doit(MainActivity.java:31)
...
我
为什么会得到那个该死的不执行发现原生???
Why do I get that damn "No implementation found for native"???
推荐答案
由于您的JNI函数是C ++源文件中,它需要被声明为externC是用JNI兼容。否则,C ++名称重整将得到动态链接的方式。
Since your JNI function is in the C++ source file, it needs to be declared as extern "C" to be compatible with JNI. Otherwise, the C++ name mangling will get in the way of dynamic linking.
此外,您的本地方法没有返回值。这应该是一个编译错误。
Also, your native method does not return a value. It should be a compilation error.
因此,与替换C函数:
So replace the C function with:
extern "C" {
jfloat Java_com_example_shit_MainActivity_pi(JNIEnv * env, jobject obj) {
return 3.14;
}
}
这篇关于Android的NDK。未找到本地LCOM实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!