我正在嘗試編寫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