'How can mercurial be run on android?

This page documents running an old version (1.8.4) of mercurial but says

"(later versions need an unavaliable python module named grp)"



Solution 1:[1]

This is the way I did it (but am still interested to hear of alternative ways) using an Ubuntu 16.04 machine and a intel 64bit android emulator running on Windows 7, using mercurial 3.7.3

  1. Using an Ubuntu system, follow these instructions for creating 2.7 version of python capable of running hg.

  2. Copy python onto android device into an app files directory (so it can be executed)

    on windows host

    adb push python279.x86_64 /sdcard

    adb -e shell

    on android device

    cd /data/user/0/$SOMEAPPDIR/files

    cp -Rav /scard/python279.x86_64 .

    make python excutable

    chmod +x python279.x86_64/bin/python2.7

    set some env vars need to make python run on android

    export LD_LIBRARY_PATH=/data/user/0/$SOMEAPPDIR/files/python279.x86_64/lib

    export LD_PRELOAD=libffi.so:libbz2.so

    export PATH=$PATH:/data/user/0/$SOMEAPPDIR/files/python279.x86_64/bin

Python should now be able to be run with python2.7

enter image description here

  1. Build mercurial on Ubuntu host.

    download mercurial 3.7.3

    uz mercurial-3.7.3.tar.gz

    cd mercurial-3.7.3 && make all

    HOME=$PWD/dist make install

  2. Make minor modifications

    cd dist/mercurial-3.7.3/dist/lib/python/mercurial

    rm *.so

    cp pure/*.py .

    Edit posix.py and delete the "import grp" line.

  3. copy mercurial onto android device

    on windows host

    adb push dist /sdcard

    adb -e shell

    on android device

    cd /data/user/0/$SOMEAPPDIR/files

    cp /sdcard/dist .

    alias hg to make it easy to use

    alias hg='python2.7 /data/user/0/$SOMEAPPDIR/files/dist/bin/hg'

Hg should now be possible to use on android device.

It's even possible to clone remote repos but I also had to pass the --insecure flag to bypass ssl errors.

enter image description here

Solution 2:[2]

The answer made on "Feb 15 '17" works fine however there is one fairly big drawback. This answer address this drawback and is intended to be used in conjunction with the previous answer.

The problem

This procedure:

rm *.so

cp pure/*.py .

removes the native libraries and uses the python 'pure' implementation of these libraries instead. This causes major performance problem when working with large repositories, especially on slower android devices.

The solution

Cross compiling mercurial with android ndk, produces native libraries that can be used on android.

I've added some helper scripts to a mercurial 4.8.2 fork to make cross compiling easier.

Linux instructions:

  1. Clone the repo

    hg clone https://bitbucket.org/hindlemail/hg-stable-android/

  2. update to 331892efe015

    hg update -r 331892efe015

  3. Set these for environment variables with appropriate values:

    provide location of android NDK

    ANDROID_NDK="$HOME/Android/android-ndk-r13b"

    specify build arch - (armeabi, x86, x86_64, arm64)

    ARCH="armeabi"

    specify target android sdk verison

    PLATFORM="android-22"

    specify output of cross compiled python.

    (see answer from Feb 15 '17" for more info )

    PYTHONDIR="/usr/local/android/install/python279.arm22"

  4. Run crosscompile.sh

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 StayOnTarget