busybox應用於android系統

http://blog.csdn.net/andyhuabing/article/details/6645992

由於Android自帶的toolbox(位於/system/bin中)也太簡略了點,有些命令如find,Android並不支持或者支持得不好。所以有必要爲Android加入busybox工具,通過編譯得到一個可以在Android裏面運行的busybox工具,我們就可以使用衆多常見的linux命令了,如find,touch等。


1、下載busybox源碼或者從廠商給的SDK中獲取到

2、下載交叉編譯器或者使用SDK工具鏈,保證與平臺使用的一致即可,否則arch或version不同導致命令執行失敗

3、開始編譯,進入busybox源碼目錄.

先執行make menuconfig命令對編譯過程進行配置.  過程如下:

Busybox Settings -> Build Options ->

     [*] Build BusyBox as a static binary (no shared libs) 這個要選上,因上這樣子編譯出來的busyBox纔是可以獨立運行的。
     (/home/jo/tool/arm-2008q3/bin/arm-none-linux-gnueabi-) Cross Compiler prefex 這是交叉編譯器的"路徑+前綴",要根據具體的情況來設置。
     Busybox Settings -> Installation Options->
     [*] Don’t use /usr        這樣子編譯出來的busybox纔不會安裝到你主機的/usr目錄下。一定要選上。

  如果編譯過程中產生無法找到頭文件的錯誤, 可指定交叉編譯器用到的頭文件所在路徑,使用-I 命令即可

  make install 可生成默認爲./_install目錄下面

4、安裝busybox

     一般將busybox下面的命令放在out....下面的system目錄下,注意busybox中很多命令都是軟鏈接的,所以不要使用window的copy命令,使用linux cp -fR命令,如果一定要在window下使用先在linux下打包再解包使用。

如下所示:

lrwxrwxrwx 1 root root      7 05-25 13:59 time -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 timeout -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 top -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 touch -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 tr -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 traceroute -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 traceroute6 -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 true -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 tty -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 ttysize -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 udpsvd -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 umount -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 uname -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 uncompress -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 unexpand -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 uniq -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 unix2dos -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 unlzma -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 unlzop -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 unzip -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 uptime -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 usleep -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 uudecode -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 uuencode -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 vi -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 vlock -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 volname -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 wall -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 watch -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 wc -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 wget -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 which -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 who -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 whoami -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 xargs -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 yes -> busybox
lrwxrwxrwx 1 root root      7 05-25 13:59 zcat -> busybox

如果不是這樣子的就是錯的或者其大文件size爲0也是錯的。

5、使用 修改/init.rc文件設置環境變量

  要提醒的是, 修改PATH環境變量的時候, 應該把busybox常用命令的路徑"/system/busybox/bin"放在Android的常用命令路徑"/system/bin"的前面, 否則, 先查找得到的將不是busybox的命令,  可以這樣設置:

export PATH/system/busybox/bin:/system/busybox/sbin: /sbin:/system/sbin:/system/bin:/s


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章