debian linux android ndk compile env setup

122 篇文章 1 订阅
109 篇文章 0 订阅

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");
    }

}

 

 


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值