Recently, Android-based IPv6 development and testing require tools such as ping, ping6, NSlookup, and traceroute6 provided in busybox. After tests, we found that there are many articles on cross-compiling busybox and putting it into Android. You can also download the cross-compiled busybox directly. However, because both of them are statically compiled busybox and linked to the standard glibc, some functions cannot run normally in Android. For example: # busybox Ping www.baidu.com
Android does not use glibc as the C library, but uses bionic libc developed by Google. Its official toolchain is based on Bionic libc rather than glibc. Compared with glibc, bionic libc has the following features:
- Use BSD license instead of glibc GPL license;
- The size is only about 200 K, half smaller than glibc, and faster than glibc;
- Implements a smaller and faster pthread;
- Provides important functions required by Android, such as "getprop" and "logi;
- POSIX standards are not fully supported, such as C ++ exceptions and wide chars;
- Libthread_db and libm implementations are not provided
What I want to do here is compile busybox Based on Bionic libc to provide better support for network-related tools. Internet search found that some people have done a lot of work on the transplantation of busybox and have done their own work, such:
Their articles and source code have been studied and tried. We can easily port busybox to Android based on the cyanogenmod source code, enable IPv6-related functions, and do not need to replace libc. So. The following is a summary of my porting steps and experience:
1. Download the modified busybox source code of cyanogenmod and decompress it to the <SRC>/external/busybox directory.
: Http://github.com/CyanogenMod/android_external_busybox
2. Compile busybox and correct compilation errors
Run # Make-J4 busybox in the root directory of the andorid source code.
Possible first-class compilation errors are as follows:
In file encoded ded from external/busybox/coreutils/DF. c: 25: <br/> bionic/libc/include/mntent. h: 48: Error: Expected '=', ';', 'asm 'or' _ attribute _ 'before 'struct '<br/>
The solution is to include the header file stdio. h In the error file. For example, add
# Include <stdio. h>
Files with similar compilation errors may be:
Coreutile/DF. C <br/> util-Linux/mount. C <br/> util-Linux/umount. c
The second possible compilation error is as follows:
External/busybox/Shell/ash. C: 12714: Error: 'rlim _ t' undeclared (first use in this function)
The error occurs because you are using an earlier Android version, which is not defined by rlim_t. The solution is to add <SRC>/bionic/libc/include/sys/resource. h
Typedef unsigned long rlim_t;
See <SRC>/bionic/libc/include/sys/resource. h file in froyo.
The third possible compilation error is as follows:
Busybox/networking/ntpd. C: 1458: Undefined reference to 'adjtimex'
The error occurs because the adjtimex, stime, Swapon, swapoff, sysinfo, and getsid functions are not defined in bionic. The solution is to modify Android. mk and add
Cyanogen_bionic: = true
3. Copy the compiled busybox to the mobile phone/system/xbin/directory for testing.
# ADB push busybox/system/xbin/
Appendix: compiled busybox binary (IPv6 supported)