about compiling python for android

6 篇文章 0 订阅
5 篇文章 0 订阅

https://code.google.com/p/python-for-android/wiki/BuildingPython

http://mdqinc.com/blog/2011/09/cross-compiling-python-for-android/



Introduction

How to build Python for Android.

Details

For linux

Download and install Android NDK.

Grab the latest Py4A Source.

The build script needs to be able to find both ndk-build and arm-eabi-strip. Here is an example of how to set your path:

export ANDROID_NDK=~/android-ndk-r5
export PATH=$PATH:$ANDROID_NDK:$ANDROID_NDK/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86

Then, to actually build python:

bash build.sh

See: BuildingModules for how to build modules.

Comment by nothanks...@googlemail.com Jul 29, 2011

29/7/11 the build.sh system is broken. it fails after compilaton

Comment by yimin....@gmail.com Sep 30, 2011

I was using android-ndk-r6b. To complete build, I have to

1. in build.sh
+mv ${PYTHONSRC} temp
if [ ! -d ${PYTHONSRC} ]; then
...
fi
+cp temp/* ${PYTHONSRC}/ -rf

2. in build.py
def strip(path):
-  run('arm-eabi-strip %s' % path)
+  run('arm-linux-androideabi-strip %s' % path)
Comment by ma...@bernawebdesign.ch Apr 17, 2012

for ndk r6b you need comment 1 above, comment 2 has been applied to source already. as well, the PATH needs to be:

export ANDROID_NDK=~/android-ndk-r6b
export PATH=$PATH:$ANDROID_NDK:$ANDROID_NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/
Comment by zouji...@gmail.com May 13, 2012

Hi Robbie and all, I have built the Py4A for x86 successfully, please refer to the following steps:

0. Enter the python-build folder, then modify setup.cfg : set linux-x86

1.1 Modify the build.sh - Backup the python-src to temp, then restore it if ! -d temp ; then

mv ${PYTHONSRC} temp
fi rm -rf ${PYTHONSRC} if  ! -d ${PYTHONSRC} ; then
.......
fi cp temp/  ${PYTHONSRC} -rf

1.2 Create the App_x86.mk as below: APP_ABI := x86

1.3 Mdify the ndk-build in build.sh file ndk-build NDK_APPLICATION_MK=${CWD}/App_x86.mk

1.4 Specify the x86 output folders in build.sh file mv obj/local/x86/python ${OUT}/usr/bin mv obj/local/x86/lib.so ${OUT}/usr/lib mv obj/local/x86/.so ${OUT}/usr/lib/python2.6/lib-dynload

2. Modify build.sy - specify the i686 strip def strip(path):

  1. un('arm-linux-androideabi-strip %s' % path)
run('i686-android-linux-strip %s' % path)

3. Modify libffi/Android.mk - replace all arm with x86

Create the linux-86 folder (Copy the linux-arm folder) Modify the libffi/linux-86/ffi.h, replace the arm with x86 Modify the libffi/include/ffi_real.h as below:
#if CONF_HAVE_LONG_DOUBLE // android changed #define FFI_TYPE_LONGDOUBLE 4 #else #define FFI_TYPE_LONGDOUBLE 4 //FFI_TYPE_DOUBLE //Zou Jinde #endif

4. Modify openssl/crypto/Android.mk:

Remove all arm lines Remove mem_dbg.c \ Remove dyn_lck.c \ Remove ex_data.c \ Remove cpt_err.c \ Remove all  .c lines in subfolders

5. Modify openssl/ssl/Android.mk

only remain the kssl.c, and remove all other  .c lines

6. Modify python/jni/modules.mk, remark the following lines #$(call import-module, openssl) #LOCAL_PATH := $(PYTHON_SRC_PATH) #LOCAL_C_INCLUDES += $(PYTHON_SRC_PATH) $(PYTHON_SRC_PATH)/Include $(OPENSSL)/include $(OPENSSL) #LOCAL_MODULE := ssl #LOCAL_MODULE_FILENAME := ssl #LOCAL_SRC_FILES := Modules/ssl.c #LOCAL_SHARED_LIBRARIES := libpython2.6 libcrypto libssl #include $(BUILD_SHARED_LIBRARY)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值