在本篇文章之前,必须确保你的cdt、cygwin、ndk的环境已经搭建好,及确保你的JNI环境已经搭建好。。
1、MainActivity
package com.njupt.ndkhelloworld1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity {
	static{//在雷第一次被创建的时候执行
		System.loadLibrary("zhangzetian");//将生成的so文件加载到JVM中
	}
	
	public native String helloFromC();//这里只需声明,实现是在Hello.c文件中...
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}
	public void click(View view){
		Toast.makeText(this, helloFromC(), 1).show();
	}
	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}2、新建jni/Hello.c
#include <stdio.h>
#include <jni.h>//这个必须要有...在这里面我们可以查看java的数据类型的对应关系
/**
 *jstring: 返回值类型
 *Java_com_njupt_ndkhelloworld1_MainActivity_helloFromC: 命名规则为:Java_包名_类名_方法名(JNIEnv* env,jobject obj)
 */
jstring Java_com_njupt_ndkhelloworld1_MainActivity_helloFromC(JNIEnv* env,jobject obj){
	return (*(*env)).NewStringUTF(env,"hello from zhangzetian...");
}3、在jni目录下新建Android.mk文件
LOCAL_PATH := $(call my-dir)
   include $(CLEAR_VARS)
   LOCAL_MODULE    := zhangzetian   
   LOCAL_SRC_FILES := Hello.c
   include $(BUILD_SHARED_LIBRARY)4、在cygwin下进入到工程目录中
输入命令ndk-build,这是并对refresh工程
这时候运行项目便能成功调用到c中的方法










