我正在尝试编写NDK基本应用程序以了解NDK如何工作。我在MainActivity中有一个文本视图和一个按钮,并且有一个库类HelloWorldLib.java,它们具有静态本机函数helloWorld。我创建了头文件并将其复制并在jni文件夹中创建了“.c”文件。没有规则制定目标 - Android中的新增功能NDK
当我通过ndk-build构建时,出现错误“无法制定目标”错误。我检查了很多帖子并回答,但没有任何工作。
我包含一个test.c空文件,如下面的链接所示,并且能够构建项目,但是,当我运行我的应用程序时,出现“找不到本机实现”的错误,因为我有实施。
https://code.google.com/p/android/issues/detail?id=66937
OnClick from where HelloWorldLib is called.
public void onClick(View v) {
// TODO Auto-generated method stub
String inNDK = HelloWorldLib.helloWorld();
tv.setText(inNDK);
}
HelloWorldLib where native is funciton is defined.
public class HelloWorldLib {
public native static String helloWorld();
static{
System.loadLibrary("com.example.androidndk_HelloWorldLib");
}
}
header file created by Javah -jni
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_example_androidndk_HelloWorldLib */
#ifndef _Included_com_example_androidndk_HelloWorldLib
#define _Included_com_example_androidndk_HelloWorldLib
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_example_androidndk_HelloWorldLib
* Method: helloWorld
* Signature:()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_example_androidndk_HelloWorldLib_helloWorld
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
C file copied from .h and then modified.
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <com_example_androidndk_HelloWorldLib.h>
#include <string.h>
extern "C" {
JNIEXPORT jstring JNICALL Java_com_example_androidndk_HelloWorldLib_helloWorld
(JNIEnv *env, jclass clazz){
return (*env)->NewStringUTF(env, "Hello from JNI ! Compiled with ABI");
}
Andoid.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := com.example.androidndk_HelloWorldLib.c
LOCAL_MODULE := com.example.androidndk_HelloWorldLib
include $(BUILD_SHARED_LIBRARY)
The error i am getting in the command prompt is shown below:
D:\Users\gabhatia\Desktop\Android SDK\MyWorkspace\AndroidNDK>ndk-build
make.exe: *** No rule to make target `jni/com.example.androidndk_HelloWorldLib.c
', needed by `obj/local/x86/objs/com.example.androidndk_HelloWorldLib/com.exampl
e.androidndk_HelloWorldLib.o'. Stop.
我不知道在那里我得到错误的,但任何帮助,将不胜感激。
谢谢。 GB。
对不起,这超过一年的雷达。我希望你的问题早已得到解决。在你的文章中,并不清楚'com.example.androidndk_HelloWorldLib.c'文件在文件系统中的位置,但是** ndk-build **正好在Android.mk **旁边查找它。 – 2015-11-06 12:22:06