from pythonforandroid.toolchain import Recipe, current_directory, shprintfrom os.path import join, realpathimport sh
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
class Bz2Recipe(CompiledComponentsPythonRecipe): version = '1.0.6' md5sum = '00B516F4704D4A7CB50A1D97E6E8E15B'.lower()
# call_hostpython_via_targetpython = True
install_in_hostpython = True depends = []
def should_build(self, arch): return True
def build_arch(self, arch): with current_directory(self.get_build_dir(arch.arch)): env = arch.get_env()
mkfile = open('Makefile-libbz2_so', 'r').read() with open('Makefile', 'w') as fp: mkfile = mkfile.replace( "$(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.{v} $(OBJS)".format(v=self.version), "$(CC) -fPIC -fpic -shared -Wl,-soname -Wl,libbz2.so -o libbz2.so $(OBJS)", ).replace( "PREFIX=/usr/local", "PREFIX=" + realpath('.') )
fp.write(mkfile)
shprint(sh.make, _env=env)
self.install_libs(arch, 'libbz2.so')
def include_flags(self, arch): bz2_includes = join(self.get_build_dir(arch.arch), 'include')
return (' -I' + bz2_includes)
def link_dirs_flags(self, arch):
return ' -L' + self.get_build_dir(arch.arch) + ' -L' + self.get_build_dir(arch.arch) + '/lib'
def link_libs_flags(self): return ' -lbz2'
def get_recipe_env(self, arch): env = super(Bz2Recipe, self).get_recipe_env(arch) env['NDK_PROJECT_PATH'] = self.get_build_dir(arch.arch) return env
recipe = Bz2Recipe()
import shfrom pythonforandroid.python import GuestPythonRecipefrom pythonforandroid.recipe import Recipefrom pythonforandroid.logger import info
class Python3Recipe(GuestPythonRecipe): ''' The python3's recipe.
.. note:: This recipe can be built only against API 21+. Also, in order to build certain python modules, we need to add some extra recipes to our build requirements:
- ctypes: you must add the recipe for ``libffi``.
.. versionchanged:: 0.6.0 Refactored into class :class:`~pythonforandroid.python.GuestPythonRecipe` '''
version = '3.7.1' name = 'python3'
patches = ["patches/fix-ctypes-util-find-library.patch"]
if sh.which('lld') is not None: patches = patches + ["patches/remove-fix-cortex-a8.patch"]
depends = ['hostpython3', 'sqlite3', 'openssl', 'libffi', 'bz2'] conflicts = ['python3crystax', 'python2']
configure_args = ( '--host={android_host}', '--build={android_build}', '--enable-shared', '--enable-ipv6', 'ac_cv_file__dev_ptmx=yes', 'ac_cv_file__dev_ptc=no', '--without-ensurepip', 'ac_cv_little_endian_double=yes', '--prefix={prefix}', '--exec-prefix={exec_prefix}')
def should_build(self, arch): return True
def set_libs_flags(self, env, arch): env = super(Python3Recipe, self).set_libs_flags(env, arch)
def add_flags(include_flags, link_dirs, link_libs): env['CPPFLAGS'] = env.get('CPPFLAGS', '') + include_flags env['LDFLAGS'] = env.get('LDFLAGS', '') + link_dirs env['LIBS'] = env.get('LIBS', '') + link_libs
if 'openssl' in self.ctx.recipe_build_order: recipe = Recipe.get_recipe('openssl', self.ctx) self.configure_args += \ ('--with-openssl=' + recipe.get_build_dir(arch.arch),)
if 'bz2' in self.ctx.recipe_build_order: info('Activating flags for bz2') recipe = Recipe.get_recipe('bz2', self.ctx)
add_flags(recipe.include_flags(arch), recipe.link_dirs_flags(arch), recipe.link_libs_flags() )
return env
recipe = Python3Recipe()
ModuleNotFoundError: No module named '_bz2'