How to Cross Compile the Bash shell for Android 1.5 (为Android平台编译Bash shell)


原文网址


How to Cross Compile the Bash shell for Android 1.5

Introduction:
I just got a new G1 Android phone, and since it runs Linux I just had to get the Bash shell running on it, the built in shell would just not do.  I do need my tab completion after all. Cross compilation is the process of compiling software on one platform that is meant to run on another.  With the following an ARM executable is compiled on a x86 Linux machine.

Requirements (Not sure if all this is needed, but it is what I used):

Step 1: Connect your pc to your phone with the SDK
You first have to be able to connect to your computer with adp which is included with the sdk.  To do this with Ubuntu Januty Jackalope you first need to create a /etc/udev/rules.d/51-android.rules file with the following contents:

1. SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"

After this run the following to restart udev: ‘sudo /etc/init.d/udev reload’. Lastly, on your phone make sure Settings :: Applications :: Development :: USB Debugging is enabled and the plug in your phone.  When you run ‘./adp devices’ you should see a device listed.

Step 2: Build the Bash Shell
After installing ARM toolkit in /home/kbrandt/bin/arm-toolkit (used for this example) set the following environment variables in your shell.

1. CC='/home/kbrandt/bin/arm-toolkit/bin/arm-none-linux-gnueabi-gcc'
2. PATH="$PATH:$HOME/bin/"

Then cd to the directory where you extracted the Bash source and run the following:

1. ./configure --prefix=/opt/arm_bash/ -host=arm-linux --enable-static-link --without-bash-malloc

Assuming that worked, edit the ‘Makefile’ file and change ‘CFLAGS = -g -O2′ to ‘CFLAGS = -g -O2 -static’ and then run ‘make’. If this works, it should create a bash executable in the current directory. You can verify that this has been compiled for the ARM architecture with ‘file bash’. This should return:

bash: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped

Step 3: Copy the File to your android.
From the host computer in the tools directory of the SDK run ‘./adb push ~/src/bash-4.0/bash /data/’ to copy the executable to the phone. If you try to copy it to your sdcard, make sure the sdcard is not mounted with the noexec mount option as this disables the executable permission bit.

Step 4: Run, Enjoy, and Find Bugs.
You can now connect to your phone with ‘./adp shell’ and cd to the data directory and run ‘./bash’ and you should get a bash prompt.  You might need to ‘chmod 555 bash’ if you get permission denied.

References:
http://jiggawatt.org/badc0de/android/index.html


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译 OpenSceneGraph (OSG) for Android 需要使用交叉编译工具链(cross-compilation toolchain),可以使用 Android NDK 中提供的工具链来完成。以下是编译 OSG 的大致步骤: 1. 下载并安装 Android NDK,可以从官网下载。 2. 下载 OSG 的源代码,可以从官网下载。 3. 解压 OSG 源代码,进入源代码目录。 4. 设置环境变量,使得编译器可以找到 Android NDK 中的工具链,例如: ``` export ANDROID_NDK=$HOME/android-ndk-r10e export PATH=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin:$PATH export CC=arm-linux-androideabi-gcc export CXX=arm-linux-androideabi-g++ ``` 其中 `$HOME/android-ndk-r10e` 是 Android NDK 的安装路径。 5. 运行 cmake 命令生成 Makefile: ``` mkdir build_android cd build_android cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ -DANDROID_ABI="armeabi-v7a" \ -DANDROID_NATIVE_API_LEVEL=android-14 \ -DCMAKE_INSTALL_PREFIX=/path/to/install/directory \ .. ``` 其中 `-DANDROID_ABI="armeabi-v7a"` 表示编译为 armeabi-v7a 架构,`-DANDROID_NATIVE_API_LEVEL=android-14` 表示使用 Android 14 的 API 级别。`-DCMAKE_INSTALL_PREFIX` 表示安装路径。 6. 运行 make 命令编译 OSG: ``` make -j4 ``` 其中 `-j4` 表示使用 4 个线程进行编译。 7. 运行 make install 命令安装 OSG: ``` make install ``` 至此,OSG 的编译就完成了。 如果需要编译 osgEarth,可以按照类似的步骤,先编译 OSG,再编译 osgEarth。在 cmake 命令中需要添加 `-DOSG_DIR=/path/to/osg/install/directory` 参数,指定 OSG 的安装路径。例如: ``` cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \ -DANDROID_ABI="armeabi-v7a" \ -DANDROID_NATIVE_API_LEVEL=android-14 \ -DCMAKE_INSTALL_PREFIX=/path/to/install/directory \ -DOSG_DIR=/path/to/osg/install/directory \ .. ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值