如何解决 Android NDK 中的 java.lang.UnsatisfiedLinkError? [英] How to resolve the java.lang.UnsatisfiedLinkError in NDK in Android?
问题描述
我是android ndk开发的新手.我已经通过了ndk android的文件系统.在这里,解释我做了什么.1) 我创建了一个名为jni"的文件夹,然后创建了 2 个名为 Android.mk 和 ndkfoo.c 的文件.
I am new in ndk development in android.I have gone through the file system of ndk android. Here, explaining what i have done. 1) i have created a folder named "jni" then create 2 file named Android.mk and ndkfoo.c.
在 Android.mk 中
In Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_MODULE := ndkfoo
LOCAL_SRC_FILES := ndkfoo.c
include $(BUILD_SHARED_LIBRARY)
在 ndkfoo.c 中
and in ndkfoo.c
#include <string.h>
#include <jni.h>
jstring Java_com_mindtherobot_samples_ndkfoo_NdkFooActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) {
return (*env)->NewStringUTF(env, "Hello from native code!");
}
然后我创建了 NdkFooActivity 类,我在其中编写了
then i have created NdkFooActivity class, in which i have written
// load the library - name matches jni/Android.mk
static {
System.loadLibrary("ndkfoo");
}
但是现在当我在 xp 中从 cygwin 构建时,它会成功创建 .so 文件,然后我作为 android 应用程序运行.它给了我 LOGCAT 中的 java.lang.UnsatisfiedLinkError.
But now when i build from cygwin in xp it creates .so file successfully then i run as android application. It gives me java.lang.UnsatisfiedLinkError in LOGCAT.
所以,请让我知道我错在哪里.
So, Please let me know where i am wrong.
提前致谢,
推荐答案
我想你忘记改包名了.
Java_com_mindtherobot_samples_ndkfoo
Java_com_mindtherobot_samples_ndkfoo
它应该是你在创建项目时指定的包.
It should be your package what you have specified creating project.
这篇关于如何解决 Android NDK 中的 java.lang.UnsatisfiedLinkError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!