Android 的toolbox没有自动补齐,命令少,对于开发人员还是需要busybox,直接移植官方的busybox会有很多问题,这里简单阐述cyanogenmod提供的针对android bionic 库的android源码的移植及添加方法,方便大家开发使用。

Android并没有采用glibc作为C库,而是采用了Google自己开发的Bionic Libc,它的官方Toolchain也是基于Bionic Libc而并非glibc的。与glibc相比,Bionic Libc有如下一些特点:

Ø 采用BSD License,而不是glibc的GPL License;

Ø 大小只有大约200k,比glibc差不多小一半,且比glibc更快;

Ø 实现了一个更小、更快的pthread;

Ø 提供了一些Android所需要的重要函数,如”getprop”, “LOGI”等;

Ø 不完全支持POSIX标准,比如C++ exceptions,wide chars等;

Ø 不提供libthread_db 和 libm的实现

1. 下载cyanogenmod修改过的busybox源码,并解压到源码external/busybox目录

位置:https://github.com/CyanogenMod/android_external_busybox

目录内容如下:

thomas@thomas-TCL:~/tegra2_IAC/tegra2_IAC/external/CyanogenMod-android_external_busybox-995d0d3$ ls

android AUTHORS Config.in e2fsprogs include-full libpwdgrp Makefile.custom networking scripts TODO Android.mk busybox-full.links console-tools editors include-minimal LICENSE Makefile.flags printutils selinux TODO_config_nommu applets busybox-full.sources coreutils examples init loginutils akefile.help procps shell util-linux arch busybox-minimal.links debianutils findutils INSTALL mailutils miscutils README sysklogd archival busybox-minimal.sources docs include libbb Makefile modutils runit testsuite

2. 编译busybox并修正编译错误:

先在android源码根目录执行:source build/envsetup.sh

进入目录:external/CyanogenMod-android_external_busybox-995d0d3/

执行:mm(单独编译模块)

3. 编译过程中遇到一个问题

问题描述:busybox/networking/ntpd.c:1458:undefinedreferenceto`adjtimex'

出错原因:bionic中没有定义adjtimex,stime,swapon,swapoff,sysinfo,getsid等函数。

解决方法:修改Android.mk,增加 CYANOGEN_BIONIC:=true

4. 安装、创建busybox shell 链接打包:

编译通过,依据Android.mk中的变量 LOCAL_MODULE_PATH := $(PRODUCT_OUT)/utilities 可知,编译出来目标文件busybox在out/target/product/$(platform_name)/utilities/目录下;

进入out/target/product/$(platform_name)/utilities/目录下,创建链接便于进入busybox shell环境,执行:ln -s busybox ash,将busybox 和 ash 一起复制到system/bin/目录下,一起打包进文件系统system.img(链接文件和链接目标文件必须一起打包);

5. 烧录到产品板使用:

usb 或网络链接adb 之后,adb shell ,之后执行ash 即可进入busybox shell,操作就和pc的linux环境差不多了,可以使用tab键自动补齐,和其他一些busybox的命令;

thomas@thomas-TCL:~/tegra2_IAC/tegra2_IAC$ adb shell

# ash

~ # net

netcfg netd netperf netserver netstat

~ # netcfg

lo UP 127.0.0.1 255.0.0.0 0x00000049

eth0 UP 192.168.20.246 255.255.255.0 0x00001043

~ #

另外,有网友在编译过程中出现其它问题,这里也一并列具出来,供参考;

6. 其它编译问题:

问题1描述:In file included from external/busybox/coreutils/df.c:25: bionic/libc/include/mntent.h:48: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'struct'

解决方法:在出错的文件中,包含头文件stdio.h。

例如在df.c中增加#include <stdio.h>

类似的编译出错的文件可能会有:coreutile/df.c util-linux/mount.c util-linux/umount.c

问题2描述: external/busybox/shell/ash.c:12714: error: 'rlim_t' undeclared (first use in this function)

原因分析:使用的是早期的Android版本,其中rlim_t没有定义。

解决方法:在bionic/libc/include/sys/resource.h中增加

typedefunsignedlongrlim_t;

typedef unsigned long rlim_t;

可以参考Froyo bionic/libc/include/sys/resource.h文件。

参考:http://www.cublog.cn/u3/95001/showart_2339184.html

更多相关文章

  1. Android中系统自带数据库文件中的多表联合查询疑问
  2. Android遇到java.lang.RuntimeException: Binary XML file line
  3. Android(安卓)自定义水平进度条的圆角进度
  4. dex替换方式实现热修复
  5. 基于Android(安卓)5.1系统的nfc读卡驱动和上层的调试记录,nfc移植
  6. Ionic cordova Android定位相关问题的小记录
  7. windows系统上安装与使用Android(安卓)NDK r5
  8. Android(安卓)Debug Bridge
  9. android apk 防止反编译技术第二篇-运行时修改字节码

随机推荐

  1. Android Studio 运行项目 报错误:You need
  2. Android中如何实现高亮显示即选中状态
  3. Android 3.1 r1 API中文文档(6)――ImageVi
  4. 笔试碎片
  5. Android 开发之日志打印封装log
  6. Android Framework架构浅析之【近期任务
  7. Android UI 介绍1
  8. android device ID获取
  9. 在Android Studio中使用Kotlin。
  10. android 在一个应用中启动另一个应用