1.Download NDK
go to Android Development site and download
NDK & SDK
http://developer.android.com/sdk/ndk/index.html
go to Cygwin site and download
http://cygwin.com/install.html
2. Install(Cygwin)
1. Choose A Download Source
Install from Internet
2. Select Root Install Directory
to use as a root(Z:Coding\’cygwin’)
3. Select Local Package Directory
to store the installation files
4. Select Your Internet Connection
Direct Connection
5. Choose A Download Site
Choose a site
6. Select Packages
Devel
gcc-core : C compiler
gcc-g++ : C++ compiler
make
Editors
vim
7. Some pakages depend on what you’ve chosen will be selected
8. Install
2. Install(NDK)
1. Install SDK
2. Install NDK inside cygwin home directory
(Z:\Coding\cygwin\home\scott\’android-ndk-r5b’)
3. Example1 – C
1.Make a Android project inside cygwin folders
(Z:\Coding\cygwin\home\scott\’ppp’)
2. Make a JNI folder at ppp
3. In JNI folder, make 2 files
(Android.mk, hello.c)
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello
//module name
LOCAL_SRC_FILES := hello.cpp //C file name
include $(BUILD_SHARED_LIBRARY)
3. In JNI folder, make 2 files
(Android.mk, hello.c)
hello.c
#include <string.h>
#include <jni.h>
jstring
Java_com_android_ppp_ppp_hello(JNIEnv* env, jobject
thiz)
//(Java_pakage name_class name_method name)
{
return (*env)->NewStringUTF(env, "Hello from JNI
C!!!");
}
3. Open cygwin and go to the root project
/home/scott/ppp
4. Compile
$ ~scott/android-ndk-r5b/ndk-build
( or to use as an easy way, add the path ‘android-ndk-r5b’ then $
ndk-build)
You can see ‘libhello.so’ file in libs folders
5. Add a code in ppp.java
package com.android.TestSimple;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TestSimple extends Activity {
public native String hello();
static{
System.loadLibrary("Test");
}
public void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new
TextView(this);
tv.setText(hello());
setContentView(tv);
}
}
6. Run Android
4. Example2 – C++
3. In JNI folder, make 3 files
(Android.mk, Application.mk, Test.cpp)
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello
//module name
LOCAL_SRC_FILES := hello.cpp //C file name
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_STL :=
stlport_static
3. In JNI folder, make 3 files
(Android.mk, Application.mk, Test.cpp)
hello.c (#ifdef추가, env부분 수정)
#include <string.h>
#include <jni.h>
#include <iostream>
using namespace std;
#ifdef __cplusplus
extern "C"{
#endif
jstring
Java_com_android_TestSimple_TestSimple_hello( JNIEnv* env,jobject
thiz)
{
return
(env)->NewStringUTF("Hello
from
JNI C++!!!");
}
#ifdef __cplusplus
}
#endif
3. Open cygwin and go to the root project
/home/scott/TestSimple
4. Compile
$ ~scott/android-ndk-r5b/ndk-build
( or to use as an easy way, add the path ‘android-ndk-r5b’ then $
ndk-build)
5. You can see ‘libhello.so’ file in libs folders
4. Add a code in ppp.java
package com.android.ppp;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class ppp extends Activity {
public native String hello(); // add a native function
static{ // to loadLibrary
System.loadLibrary("hello");
// native C file name
}
public void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new
TextView(this);
tv.setText(hello());
setContentView(tv);
}
}
4. Run Android
'6. With IT > 6.2 NDK' 카테고리의 다른 글
이클립스_NDK자동 컴파일 (0) | 2012.02.09 |
---|---|
Android.mk (0) | 2012.02.02 |
static chain // dynamic chain (0) | 2011.11.03 |
NDK + eclipse + cygwin 플러그인하는방법 (0) | 2011.09.20 |
JAVA JNI & Android NDK - 설치 및 사용 (0) | 2011.06.02 |