问题描述
我要在Eclipse中创建一个JUNO基于JNI的Android项目。
I want to create a JNI based Android project in eclipse juno.
我如何使用Java和C ++创建Android的一个简单的Hello World项目。是否有任何教程,可以帮助我上面提到的应用程序使用JNI。
How can I create a simple "Hello World" Project in android by using Java and C++. Is there any tutorial that could help me to the above mentioned app by using JNI.
通过运行应用程序它显示了以下错误
By running the app it shows the following errors
推荐答案
的
这是一个伟大的教程开始与NDK。
This is a great tutorial to start with NDK.
确定这里是code的活性 -
Ok Here is the code Activity--
package com.example.ndk;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
public class MainActivity extends Activity {
static {
System.loadLibrary("NDK");
}
// declare the native code function - must match ndkfoo.c
private native String invokeNativeFunction();
@Override
public 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();
}
}
NDK.cpp
NDK.cpp
#include <string.h>
#include <jni.h>
jstring Java_com_example_ndk_MainActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) {
return (*env)->NewStringUTF(env, "Hello from native code!");
}
Android.mk
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Here we give our module name and source file(s)
LOCAL_MODULE := NDK
LOCAL_SRC_FILES := NDK.c
include $(BUILD_SHARED_LIBRARY)
把Android.mk和NDK.cpp在 JNI
文件夹
现在建库使用cygwin的(如果你在窗口开发),相同的例子提及。并运行它。
Put Android.mk and NDK.cpp in jni
folderNow build the library using cygwin (if you are developing on window), same as mention in the example. and run it.
这篇关于如何在Eclipse中创建JNI的Android项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!