android模拟器bo,在 Android 模拟器中安装 busybox
在Android模擬器中安裝busybox
【背景】:
Android?模擬器的?shell?真是難用啊,很多命令都不支持,如?find?、?grep?、?send?等等,最近正好有時間,想搗鼓搗鼓,用交叉編譯將?busybox安裝到模擬器中去。
【具體步驟】:
1)下載?busybox?源代碼,并解包
$ wget -chttp://www.busybox.net/downloads/busybox-1.7.0.tar.bz2
$ tar jxvf busybox-1.7.0.tar.bz2
2)下載交叉編譯工具,并安裝
我下載的是:?arm-2009q1-161-arm-none-eabi.bin
說明:要正確設置好?PATH?變量。
例如將?“?你的目錄?”/CodeSourcery/Sourcery_G++_Lite/bin?加到?PATH?路徑中。
3?)進入到?busybox?解壓后的源文件目錄中,修改?Makefile
將第?176?行改為:
CROSS_COMPILE????=arm-none-linux-gnueabi-
4?)進行編譯選項配置
a?、
$ make menuconfig
Busybox Settings --->
Build Options --->
[*] Build BusyBox as a static binary(no shared libs)
說明:這個選項一定要選,這樣才能把?busybox?編譯成靜態鏈接的可執行文件,運行時可以獨立于其他庫。
b?、
Installation Options --->
[*] Don't use /usr
說明:這個也一定要選,否則?make install?后,?busybox?將安裝在原來系統的?/usr?下,將你原有的命令都覆蓋了!
5?)配置好后可以編譯了,執行如下命令:
$ make
發現沒過多久,就報錯了,暈,錯誤內容如下:
applets/applets.c:20:2: warning: #warning Static linking against glibc produces buggy executables
applets/applets.c:21:2: warning: #warning (glibc does not cope well with ld --gc-sections).
applets/applets.c:22:2: warning: #warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
applets/applets.c:23:2: warning: #warning Note that glibc is unsuitable for static linking anyway.
applets/applets.c:24:2: warning: #warning If you still want to do it, remove -Wl,--gc-sections
applets/applets.c:25:2: warning: #warning from top-level Makefile and remove this warning.
applets/applets.c:26:2: error: #error Aborting compilation.
make[1]: *** [applets/applets.o]錯誤?1
make: *** [applets]錯誤?2
看到它給出了提示,說?glibc?庫不適和用來靜態編譯,最后給出解決方案就是將?applets/applets.c?中這部分內容給去掉,也就是?19-27?行。
然后再?make?進行編譯。
不多久又報錯了,看看具體錯誤:
.../compal/CodeSourcery/Sourcery_G++_Lite/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/netfilter.h:56:17: error: field 'in' has incomplete type
.../CodeSourcery/Sourcery_G++_Lite/bin/../arm-none-linux-gnueabi/libc/usr/include/linux/netfilter.h:57:18: error: field 'in6' has incomplete type
ipsvd/tcpudp.c: In function 'tcpudpsvd_main':
ipsvd/tcpudp.c:314:10: warning: ignoring return value of 'write', declared with attribute warn_unused_result
make[1]: *** [ipsvd/tcpudp.o]錯誤?1
make: *** [ipsvd]錯誤?2
看到說在我們下載的交叉編譯庫中有個頭文件中的?in?及?in6?類型不對,解決的辦法就是:
在?.../arm-none-linux-gnueabi/libc/usr/include/linux/netfilter.h?的開頭添加缺少的頭文件:#include
然后再進行編譯。(這次可以安全到最后了,呵呵)
結束后會在當前目錄下看到?busybox?這個可執行文件。
6?)編譯步驟已完成,下面就將?busybox?這個可執行文件放到?Android?模擬器下去
$ adb push busybox /system/xbin
說明:若是出現什么?read-only file system?等等之類,執行如下命令即可:
$ adb remount
要是老是不行,那就重新啟動?adb
$ adb kill-server
$ adb start-server
要是碰到什么內存不足等等,那原因就是你的那個?Android?模擬器是用?Eclipse?打開的。解決辦法就是,手動啟動你的?Android emulator?模擬器,具體如下:
$ android list avd?????#注釋:列出你所有的模擬器
$ emulator -avd your_emulator_name -partition-size 256
注意:最好放在?/system/xbin?下面,這樣當你在模擬器里使用?busybox?時不需要指定絕對路徑了,否則的話誰都會瘋掉嘛,呵呵。
7?)輸入?adb shell?進入終端,執行看看
# busybox --help
BusyBox v1.7.0 (2011-04-22 20:53:21 CST) multi-call binary
Copyright (C) 1998-2006?Erik Andersen, Rob Landley, and others.
Licensed under GPLv2.?See source distribution for full notice.
…
說明:表明我們的?busybox?已經可以執行了。但同時又有一個問題,每次輸入一個命令都要加上?busybox?,那么人又要瘋掉了,?-_-!?。解決辦法就是,我想到可以使用?alias?命令嘛,給我們所有輸入的東西都自動加上?busybox?,具體如下:
【方法?1?】:
將你所感興趣的命令集中在一個腳本中打包,例如建立內容如下的腳本:
#!/bin/sh
# set_alias1.sh?(當然你名字可以隨便改,越短越好,但不要和命令重名)
alias ls='busybox ls'
alias find='busybox find'
…
保存好后,將其?push?到模擬器中的?/system/xbin?下面,然后用?adb shell?進入到模擬器終端后執行如下命令:
# . set_alias1.sh??????????#注釋:在當前進行中執行該腳本(一定要有?"?點?"?)
【方法?2?】:
以上方法雖然能解決問題,但總覺得添加這么多東西也怪煩人的,寫個智能點的腳本:
xxx:~/code/shellcode$ cat set_alias.sh
#!/bin/bash
# set_alias.sh
pre_handle_result=$(busybox echo -n $(busybox --help) | busybox grep -v '^/t')
pre_cmds=${pre_handle_result##*[[, }
sec_cmds=$(busybox echo -n $pre_cmds | busybox sed 's/,//g')
for cmd in $sec_cmds
do
# alias cmds
alias $cmd="busybox $cmd"
done
然后將其?push?到模擬器中的?/system/xbin?下,執行過程如上。
8?)差不多了,祝使用愉快。
總結
以上是生活随笔為你收集整理的android模拟器bo,在 Android 模拟器中安装 busybox的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基地三部曲观后感
- 下一篇: Android Studio连接夜深模拟