android JNI的问题
我现在只想在手机上能够用jni显示helloworld就可以了,我按网上的步骤完成后,在手机上显示时总是死机。
我首先得是一个helloNDK
package com.example.ndktest;
public class helloNDK {
/**
* @param args
*/
static{
System.loadLibrary("NDKtest");
}
public native String sayHello();
}
#include "com_example_ndktest_helloNDK.h"
JNIEXPORT jstring JNICALL Java_com_example_ndktest_helloNDK_sayHello
(JNIEnv *env, jobject thiz){
return (*env)->NewStringUTF(env,"Hello,Welcome to NDK");
}
package com.example.ndktest;
import android.app.Activity;
import android.os.Bundle;
public class test extends Activity {
/**
* @param args
*/
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
helloNDK obj = new helloNDK();
String str = obj.sayHello();
setTitle("[" + str + "]");
}
}
package com.example.hellondk;
public class Hellondk {
static{
System.loadLibrary("helloNDK");
}
public native String sayHello();
}
package com.example.hellondk;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Hellondk obj = new Hellondk();
Log.d("MainActivity", "------>"+obj.sayHello());
setTitle(obj.sayHello());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
#include"com_example_hellondk_Hellondk.h"
JNIEXPORT jstring JNICALL Java_com_example_hellondk_Hellondk_sayHello
(JNIEnv *env, jobject thiz){
return (*env)->NewStringUTF(env,"Hello,Welcome to NDK");
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_example_hellondk_Hellondk */
#ifndef _Included_com_example_hellondk_Hellondk
#define _Included_com_example_hellondk_Hellondk
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_example_hellondk_Hellondk
* Method: sayHello
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_example_hellondk_Hellondk_sayHello
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/
LOCAL_MODULE := helloNDK
LOCAL_SRC_FILES := com_example_hellondk_Hellondk.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)