Androidã®NDK 1.5ã§HelloJNIãåããæé
å æ¥çºè¡¨ãããAndroidã®NDK(Native Development Kit)ã®ãé°ã§apkãã¡ã¤ã«ã«ã©ã¤ãã©ãªãå梱ããããã«ã½ã¼ã¹ã³ã¼ãããã¹ã¦ãã¦ã³ãã¼ãããå¿ è¦ããªããªã£ãä¸ã«ãWindowsã ãã§ãä½æ¥ã§ããããã«ãªããéçºãããªã楽ã«ãªãã¾ããã
ä»åã¯NDKã«ä»å±ãã¦ããhello-jniã¨ããåç´ãªãµã³ãã«ããã¸ã§ã¯ããWindowsä¸ã§ãã«ããå®è¡ããã¾ã§ã®æé ãã¾ã¨ãã¦ã¿ã¾ããã
æºå
cygwinã®ãã¦ã³ãã¼ããã¤ã³ã¹ãã¼ã«
- ここããã®ã¢ã¤ã³ã³ãã¯ãªãã¯ãã¦setup.exeããã¦ã³ãã¼ããã¾ãã
- setup.exeãå®è¡ããã¨ä»¥ä¸ã®ãããªç»é¢ã«ãªãã®ã§ãã次ã¸(N)ããæ¼ãã¦å ã«é²ã¿ã¾ãã
- ããã«ã次ã¸(N)ããæ¼ãã¦å ã«é²ã¿ã¾ãã
- cygwinã®rootãã£ã¬ã¯ããªãå¤æ´ããå¿ è¦ããªããã°ãä½ãå¤æ´ããã«ã次ã¸(N)ããæ¼ãã¦å ã«é²ã¿ã¾ãã
- cygwinããã±ã¼ã¸ã®ãã£ã¬ã¯ããªãå¤æ´ããå¿ è¦ããªããã°ãä½ãå¤æ´ããã«ã次ã¸(N)ããæ¼ãã¦å ã«é²ã¿ã¾ãã
- ã¤ã³ã¿ã¼ãããæ¥ç¶ã«Proxyãè¨å®ãã¦ããªããã°ãDirect ConnectionããIEã¨åãè¨å®ã使ç¨ããå ´åã¯ãUse IE5 SettingsããProxyãæåã§è¨å®ããå ´åã¯ãUse HTTP/FTP Proxyããè¨å®ããã次ã¸(N)ããæ¼ãã¦å ã«é²ã¿ã¾ãã
- ãã¦ã³ãã¼ãå ãé¸ãã§ã次ã¸(N)ããæ¼ãã¦å ã«é²ã¿ã¾ããæ¥æ¬ã®ãã¡ã¤ã³ãé¸ãã æ¹ãã¹ãã¼ãã¯éãã§ããã¾ããftpã ã¨ç¹ãããªããã¨ãå¤ãã®ã§ãhttpã®ãã®ãé¸ãã ã»ããè¯ãããã§ãã
- 以ä¸ã®ãããªç»é¢ãã§ãã®ã§ããã°ããå¾ ã¡ã¾ãã
- ã¤ã³ã¹ãã¼ã«ããããã±ã¼ã¸ãé¸æããç»é¢ã«ãªãã¾ãã
- ã¹ã¯ãã¼ã«ããã¦ããDevelãã®ã+ããã¿ã³ãæ¼ãã¦Develã®ã«ãã´ãªã®ãªã¹ããå±éãã¾ãã
- ããã«ã¹ã¯ãã¼ã«ããgccã®ããã±ã¼ã¸ãé¸æ(â»èµ¤ä¸¸ã®ãããã®é¨åãã¯ãªãã¯)ãã¾ããèªåçã«gcc-coreãªã©ã«ããã§ãã¯ãå ¥ãã¾ããããã®ã¾ã¾ã«ãã¦ããã¾ãã
- ããã«ä¸ã«ã¹ã¯ãã¼ã«ããmakeã®ããã±ã¼ã¸ãé¸æ(â»èµ¤ä¸¸ã®ãããã®é¨åãã¯ãªãã¯)ãã¾ããåããèªåçã«ä»ã®ããã±ã¼ã¸ã«ããã§ãã¯ãå ¥ãã¾ããããã®ã¾ã¾ã«ãã¦ããã¾ããããã¦ã次ã¸(N)ããæ¼ãã¦å ã«é²ã¿ã¾ãã
- ããã¨ä»¥ä¸ã®ãããªç»é¢ã«ãªãã®ã§ãå®äºããã¾ã§å¾ ã¡ã¾ãã
- ãã®ç»é¢ãåºãã°å®äºã§ãããå®äºããæ¼ãã¦çµäºãã¾ãã
Windowsç°å¢å¤æ°ã®è¨å®
ãã¹ã¯ãããä¸ã«ã§ããã®ã¢ã¤ã³ã³ããèµ·åãããã¨ãWindowsã®ã¦ã¼ã¶ã¼ã¢ã«ã¦ã³ãã®ãã£ã¬ã¯ããªãHOMEãã£ã¬ã¯ããªã«ãªããWindows XPã®å ´åã¯ãã¹ã«ã¹ãã¼ã¹ãå«ã¾ãããããå¾ã®ä½æ¥ããã¾ãããã¾ããã
ãã®çºãç°å¢å¤æ°ãHOMEããè¨å®ãã¦ããããããä»»æã®HOMEãã£ã¬ã¯ããªãæå®ãã¦ããã¾ãã
ç°å¢å¤æ°ã®è¨å®æ¹æ³
- ãã¤ã³ã³ãã¥ã¼ã¿ã®ããããã£ãéã
- ã·ã¹ãã ã®ããããã£ç»é¢ãåºãã®ã§ãã詳細è¨å®ãã¿ããé¸æãã¾ãã
- 詳細è¨å®ã®ç»é¢ã§ãç°å¢å¤æ°ããã¿ã³ãæ¼ãã¾ãã
- ç°å¢å¤æ°ã®ã¦ã¼ã¶ã¼ç°å¢å¤æ°ã®ãæ°è¦ããã¿ã³ãæ¼ãã¾ãã
- å¤æ°åã«ãHOMEããå¤æ°å¤ã«ã/home/ã¦ã¼ã¶ã¼åã(â»ã¦ã¼ã¶ã¼åé¨åã¯ä»»æ)ãå ¥åããOKã§æãã¾ãã
ããã§Windowså´ã®ç°å¢å¤æ°ã®è¨å®ã¯å®äºã§ãã
ãã¹ã¯ãããä¸ã«ã§ãã¦ããã®ã¢ã¤ã³ã³ããèµ·åãããã¨ãc:\cygwin\home\ã¦ã¼ã¶ã¼åãã£ã¬ã¯ããªãèªåçã«çæããããããHOMEãã£ã¬ã¯ããªã«ãªãã¾ãã
NDK1.5ã®ãã¦ã³ãã¼ããã¤ã³ã¹ãã¼ã«
ãã¦ã³ãã¼ããçµãã£ãããandroid-ndk-1.5_r1-windows.zipãå ç¨èªåçæãããc:\cygwin\home\ã¦ã¼ã¶ã¼åã®ãã£ã¬ã¯ããªã«å±éãã¾ãã
å±éå¾ã«
c:\cygwin\home\ã¦ã¼ã¶ã¼å\android-ndk-1.5_r1-windowsã®ããã«ãªãããã«ãã¦ãã ããã
c:\cygwin\home\ã¦ã¼ã¶ã¼å\ã«.bashrcãã¡ã¤ã«ãèªåçæããã¦ããçãªã®ã§ããã®ãã¡ã¤ã«ã®æå¾å°¾ã«
export ANDROID_NDK_ROOT=C:/cygwin/home/ã¦ã¼ã¶ã¼å/android-ndk-1.5_r1-windowsã追å ãã¦ä¿åãã¾ãã
ããã¦ãå度ãcygwinã®ã·ã§ã«ãèµ·åããã¾ããcygwinã·ã§ã«ä¸ã§ã
$ cd andoird-ndk-1.5_r1
ã¨ãã¦NDKã®ãã£ã¬ã¯ããªã«ç§»åãã
$ sh build/host-setup.shã¨å ¥åãã¾ãã
æåããã¨ãã®ããã«åºåããã¾ãã
$ sh build/host-setup.sh Detecting host toolchain. CC : compiler check ok (gcc) LD : linker check ok (gcc) CXX : C++ compiler check ok (g++) Generate : out/host/config.mk Toolchain : Checking for arm-eabi-4.2.1 prebuilt binaries Host setup complete. Please read docs/OVERVIEW.TXT if you don't know what to do.
ããã§NDKã®ã¤ã³ã¹ãã¼ã«ã¯å®äºã§ãã
hello-jniã©ã¤ãã©ãªã®ãã«ã
NDKã®appsãã£ã¬ã¯ããªã«hello-jniã®ãµã³ãã«ã¢ããªãããã¾ããä»åã¯ããããã«ããã¦ã¿ã¾ãã
cygwinã·ã§ã«ã®andoird-ndk-1.5_r1ãã£ã¬ã¯ããªã§ä»¥ä¸ã®ããã«ã³ãã³ããå®è¡ãã¾ãã$ make APP=hello-jni
æåããã¨ä»¥ä¸ã®ããã«åºåããã¾ãã$ make APP=hello-jni Android NDK: Building for application 'hello-jni' Compile thumb : hello-jni <= sources/samples/hello-jni/hello-jni.c SharedLibrary : libhello-jni.so Install : libhello-jni.so => apps/hello-jni/project/libs/armeabi
ãã®æ®µéã§ã¯ã©ã¤ãã©ãªãã¡ã¤ã«ã®çæããè¡ããããapkãã¡ã¤ã«ã¯ä½æããã¾ããã
apkãã¡ã¤ã«ãä½æããçºã«ãä»åã¯Eclipseã§hello-jniããã¸ã§ã¯ããåãè¾¼ã¿ã¾ãã
Eclipseã«hello-jniããã¸ã§ã¯ããåãè¾¼ã
- Eclipseãèµ·åãã¦ããç¶æ ã§ãCtrl+Nãã¼ãæ¼ä¸ãã¦æ°è¦ããã¸ã§ã¯ãä½æç»é¢ãéãããAndroid Projectããé¸æãã¦ãNextããã¿ã³ãæ¼ãã¾ãã
- ãCreate project from existiong sourceããé¸ã³ã¾ãã
- ãBrowseããã¿ã³ãæ¼ãã¾ãã
- NDKã解åãããã£ã¬ã¯ããªã®ä¸ã®ãapps/hello-jni/projectããé¸æãã¦ãOKããã¿ã³ãæ¼ãã¾ãã
- ã½ã¼ã¹ã³ã¼ããã¤ã³ãã¼ãããã以ä¸ã®ãããªç»é¢ã«ãªãã®ã§ããFinishããã¿ã³ãæ¼ãã¾ãã
- HelloJniããã¸ã§ã¯ããåãè¾¼ã¾ããã¨ãããlibsã®ä¸ã«libhello-jni.soãã¡ã¤ã«ãå«ã¾ãã¦ãã¾ãã
ããããã¯ãã¤ãéããæ®éã®Androidããã¸ã§ã¯ãã¨ãã¦å®è¡å¯è½ã§ãã
ããã©ã¤ãã©ãªå´ã®ã½ã¼ã¹ã³ã¼ã(~/android-ndk-1.5_r1/sources/samples/hello-jni/hello-jni.c)ãæ´æ°ããå ´åã¯ãcygwinã·ã§ã«ãã
$ make APP=hello-jni
ãå度å®è¡ãã¦ã©ã¤ãã©ãªãã¡ã¤ã«ãæ´æ°ããå¾ãEclipseã®ãProject Explorerãã®HelloJniããã¸ã§ã¯ãã®ã«ã¼ããé¸æãã¦F5ãã¼ãæ¼ä¸ããã¨ãã©ã¤ãã©ãªãã¡ã¤ã«ãæ´æ°ããããã¨ãæ¤ç¥ãããåã³ã³ãã¤ã«ãèµ°ãã¾ãã
ãã®æé ãå¿ããã¨ãapkãã¡ã¤ã«ãåçæãããªãã®ã§æ³¨æãå¿ è¦ã§ãã
Good luck!