debian linux android ndk compile env setup

1. install debian linux 6.0.6
2. edit source list file
3. setup gcc g++ compile env
apt-get install gcc g++ gdb automake make autoconf etc
4. download android ndk package
android-ndk-r8b-linux-x86.tar
5. unzip ndk and install in /opt
tar xvf android-ndk-r8b-linux-x86.tar
cp -r android-ndk-r8b /opt
6. set compile path
edit /etc/profile
ANDROID_NDK_ROOT=/opt/android/android-ndk-r8b
export PATH=$ANDROID_NDK_ROOT:$PATH

for example:

1. copy ndk sample hello-jni into my home

cp -r /opt/android/android-ndk-r8b/samples/hello-jni /home/mytest

Android.mk content is as followings.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c

include $(BUILD_SHARED_LIBRARY)

hello-jni.c file content is as followings. (modified)

#include <string.h>
#include <jni.h>

jstring
Java_hello1_world_TestHello1Activity_stringFromJNI( JNIEnv* env,
jobject thiz )
{
return (*env)->NewStringUTF(env, "Hello from JNI !");
}

2. run ndk-build in test/hello-jni directory

3. copy libs/armeabi/libhello-jni.so into local windows

4. copy libhello-jni.so into project libs\armeabi

5. open android simulator

6. compile hello1.world.TestHello1Activity project by eclipse

run hello1.world.TestHello1Activity project as android application

7. procedure is over

8. source code for java jni call

package hello1.world;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class TestHello1Activity extends Activity {
private Button btn_save;
private EditText edit_name;
private EditText edit_telno;
private EditText edit_text;

public native String stringFromJNI();

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViews();
setListensers();
InitEdit();
}

private void findViews() {

btn_save = (Button) findViewById(R.id.cm_save);

edit_name = (EditText) findViewById(R.id.cm_name);
edit_telno = (EditText) findViewById(R.id.cm_telno);
edit_text = (EditText) findViewById(R.id.cm_text);

}

private void setListensers() {

btn_save.setOnClickListener(save);


}

private OnClickListener save = new OnClickListener() {
public void onClick(View v) {


String name = edit_name.getText().toString();
String telno = edit_telno.getText().toString();

edit_text.setText(stringFromJNI() + edit_text.getText() + " " + name + " " + telno);

}
};


private void InitEdit() {
edit_name.setText(null);
edit_telno.setText(null);
}

static {
System.loadLibrary("hello-jni");
}

}


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android长截图与长图分享-(六)
  2. Android中activity切换动画的两种实现(附
  3. Android中自定义Adapter
  4. Android运行时配置更改
  5. sdcard
  6. 浅入浅出 Android 安全:第二章 Android Li
  7. 如何把多个Android Project打包成一个APK
  8. Android九环刀之RatingBar之评委请亮分
  9. Android应用程序防止被LMK干掉
  10. 升级Android SDK后ADT找不到adb.exe文件