reference from http://cheng-min-i-taiwan.blogspot.com/2010/06/android-ndk-hellojni.html
-------------------
According to system requirement, we have to install cygwin first.
http://developer.android.com/sdk/ndk/overview.html#reqs
Go to cygwin official website to get cygwin and setup it.
http://cygwin.com/install.html
If you are first time to use cygwin, you'll been asking to select which package you want to setup at the same time.
All we have to select is
- Devel/gcc
- Devel/gcc-core
- Devel/gcc-g++
- Devel/gcc-mingw-core
- Devel/gcc-mingw-g++
- Devel/make
- Devel/mingw-runtime
Next, we should download the NDK from Android website. (I download android-ndk-r5b for windows)
http://developer.android.com/sdk/ndk/index.html
Decompress NDK into cygwin install folder. (I install at C:\cygwin\)
Execute cygwin for establish folder C:\cygwin\home\[your username]
Use notepad edit file C:\cygwin\home\[your username]\.bash_profile
Append text at last of file
PATH=/android-ndk-r5b:${PATH}
NDK_ROOT=/android-ndk-r5b
NDK_Sample=/android-ndk-r5b/samples
export PATH NDK_ROOT NDK_Sample
Restart cygwin program
Go to folder which you want to build cd /android-ndk-r5b/samples/hello-jni/
Input command ndk-build
-------------------
Next, we should install Eclipse CDT(C/C++ Development Tool)
Open Eclipse, Help->Install New Software->Add->Achive
Name: CDT
Location: http://download.eclipse.org/tools/cdt/releases/galileo
Choice packages
• Eclipse C/C++ Development Tools
• CDT GNU Toolchain Build Support
• CDT GNU Toolchain Debug Support
• CDT Utilities
• Eclipse C/C++ Development Platform
Then restart Eclipse
-------------------
Now, getting start with project hello-jni
File->New->Project->Android Project
Choice Create project from existing source
Location Choice C:\cygwin\android-ndk-r5b\samples\hello-jni
Build Target Choice Android 2.2
If you've execute ndk-build at the project
It will appear the libs subdirectory.
Setting Builder
Right click mouse on project name
Properties -> Builders -> New-> Program
in label Main
- Name: Native_Builder
- Location: C:\cygwin\bin\bash.exe
- Working Directory: C:\cygwin\bin
- Arguments: --login -c "cd $NDK_Sample/hello-jni && ndk-build"
Check "Refresh resources upon completion"
Choice Specific resources, then check HelloJni\libs
in label Build Options
check Allocate Console
check Launch in background
check After"Clean"
check During manual builds
check During auto builds
check Specify working set of relevant resources,Choice Specify Resources then check HelloJni\jni
Click Apply,OK,OK
If it has be setted correctly, you'll look the message in Console perspective.
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Install : libhello-jni.so => libs/armeabi/libhello-jni.so
--------------------------------
Now, let's run the project!
沒有留言:
張貼留言