cross compile git for arm/Android
Checkout git source code using some release tag from https://github.com/git/git/releases
Compilation steps (copy/paste to bash shell)
export API_LEVEL=android-23 # Android 6.0
export COMPILER_ARCH=arm-linux-androideabi-4.9
export ANDROID_NDK=/home/usrname/adr/ndk # or your Android NDK root directory
export CC=${ANDROID_NDK}/toolchains/$COMPILER_ARCH/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
export CCOPT="-O2 -fpic --sysroot=/home/usrname/adr/ndk/platforms/$API_LEVEL/arch-arm -DANDROID -DOS_ANDROID -pie"
export CFLAGS="--sysroot=${ANDROID_NDK}/platforms/$API_LEVEL/arch-arm -DANDROID -DOS_ANDROID"
export
LDFLAGS="--sysroot=${ANDROID_NDK}/platforms/$API_LEVEL/arch-arm -fPIC
-mandroid -L${ANDROID_NDK}/platforms/$API_LEVEL/arch-arm/usr/lib
-pie" # add -pie (position independent executable) for running on
multiple phones
cd git-v2.9.3/ # enter git source code directory or checkout v2.9.3
autoconf # generate configureWorkaround configure error
You may need to modify the configure script to workaround some failure.
For example, I got
"checking whether system succeeds to read fopen'ed directory
cannot run test program while cross compiling"
I fixed this by modifying configure:
* Near above the message ""checking whether system succeeds to read fopen'ed director", put a line
cross_compiling=no
This will bypass the checks somehow.
Workaround library not found errors
You may need to modify Makefile
I got "-liconv and -lrt not found". I just comment out the lines which add -liconv and -lrt to EXTLIBS
Finally
./configure --host=arm-linux
make -j8
Known limitation
The produced git does not work with "https://" sites but still work well with git protocol.
Useful shortcut
Copy the compiled git to /system/bin/git so that we can call git everywhere
Use an environment variable setting HOME before calling git, or export it. (putting 'HOME=...' into a global /system/bin/git.sh caused 'git index-pack failed')
HOME=/data/local/tmp/my_home git clone git@github.com:username/abc.git
Comments
Post a Comment