Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pythonforandroid/archs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def get_env(self, with_flags_in_cc=True):
if self.ctx.python_recipe and self.ctx.python_recipe.from_crystax:
env['CRYSTAX_PYTHON_VERSION'] = self.ctx.python_recipe.version

env['TARGET_ANDROID_API'] = str(self.ctx.ndk_target_api)

return env


Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def _unpack_aar(self, aar, arch):

def strip_libraries(self, arch):
info('Stripping libraries')
if self.ctx.python_recipe.from_crystax:
if self.ctx.python_recipe.from_crystax or True:
info('Python was loaded from CrystaX, skipping strip')
return
env = arch.get_env()
Expand Down
172 changes: 101 additions & 71 deletions pythonforandroid/bootstraps/sdl2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pythonforandroid.toolchain import (
Bootstrap, shprint, current_directory, info, info_main)
from pythonforandroid.util import ensure_dir
from pythonforandroid.recipe import Recipe
from os.path import join, exists, curdir, abspath
from os import walk
import glob
Expand All @@ -13,7 +14,7 @@
class SDL2GradleBootstrap(Bootstrap):
name = 'sdl2_gradle'

recipe_depends = ['sdl2', ('python2', 'python3crystax')]
recipe_depends = ['sdl2', ('python2', 'python3crystax', 'python3')]

def run_distribute(self):
info_main("# Creating Android project ({})".format(self.name))
Expand All @@ -39,8 +40,8 @@ def run_distribute(self):
with current_directory(self.dist_dir):
info("Copying Python distribution")

if not exists("private") and not from_crystax:
ensure_dir("private")
# if not exists("private") and not from_crystax:
# ensure_dir("private")
if not exists("crystax_python") and from_crystax:
ensure_dir(crystax_python_dir)

Expand All @@ -52,84 +53,113 @@ def run_distribute(self):
_tail=10, _filterout="^Listing")
except sh.ErrorReturnCode:
pass
if not exists('python-install'):
shprint(
sh.cp, '-a', python_install_dir, './python-install')
# if not exists('python-install'):
# shprint(
# sh.cp, '-a', python_install_dir, './python-install')

self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
self.distribute_javaclasses(self.ctx.javaclass_dir,
dest_dir=join("src", "main", "java"))

if not from_crystax:
info("Filling private directory")
if not exists(join("private", "lib")):
info("private/lib does not exist, making")
shprint(sh.cp, "-a",
join("python-install", "lib"), "private")
shprint(sh.mkdir, "-p",
join("private", "include", "python2.7"))

libpymodules_fn = join("libs", arch.arch, "libpymodules.so")
if exists(libpymodules_fn):
shprint(sh.mv, libpymodules_fn, 'private/')
shprint(sh.cp,
join('python-install', 'include',
'python2.7', 'pyconfig.h'),
join('private', 'include', 'python2.7/'))

info('Removing some unwanted files')
shprint(sh.rm, '-f', join('private', 'lib', 'libpython2.7.so'))
shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig'))

libdir = join(self.dist_dir, 'private', 'lib', 'python2.7')
site_packages_dir = join(libdir, 'site-packages')
with current_directory(libdir):
removes = []
for dirname, root, filenames in walk("."):
for filename in filenames:
for suffix in EXCLUDE_EXTS:
if filename.endswith(suffix):
removes.append(filename)
shprint(sh.rm, '-f', *removes)

info('Deleting some other stuff not used on android')
# To quote the original distribute.sh, 'well...'
shprint(sh.rm, '-rf', 'lib2to3')
shprint(sh.rm, '-rf', 'idlelib')
for filename in glob.glob('config/libpython*.a'):
shprint(sh.rm, '-f', filename)
shprint(sh.rm, '-rf', 'config/python.o')

else: # Python *is* loaded from crystax
ndk_dir = self.ctx.ndk_dir
py_recipe = self.ctx.python_recipe
python_dir = join(ndk_dir, 'sources', 'python',
py_recipe.version, 'libs', arch.arch)
shprint(sh.cp, '-r', join(python_dir,
'stdlib.zip'), crystax_python_dir)
shprint(sh.cp, '-r', join(python_dir,
'modules'), crystax_python_dir)
shprint(sh.cp, '-r', self.ctx.get_python_install_dir(),
join(crystax_python_dir, 'site-packages'))

info('Renaming .so files to reflect cross-compile')
site_packages_dir = join(crystax_python_dir, "site-packages")
find_ret = shprint(
sh.find, site_packages_dir, '-iname', '*.so')
filenames = find_ret.stdout.decode('utf-8').split('\n')[:-1]
for filename in filenames:
parts = filename.split('.')
if len(parts) <= 2:
continue
shprint(sh.mv, filename, filename.split('.')[0] + '.so')
site_packages_dir = join(abspath(curdir),
site_packages_dir)
# if not from_crystax:
# info("Filling private directory")
# if not exists(join("private", "lib")):
# info("private/lib does not exist, making")
# shprint(sh.cp, "-a",
# join("python-install", "lib"), "private")
# shprint(sh.mkdir, "-p",
# join("private", "include", "python2.7"))

# libpymodules_fn = join("libs", arch.arch, "libpymodules.so")
# if exists(libpymodules_fn):
# shprint(sh.mv, libpymodules_fn, 'private/')
# shprint(sh.cp,
# join('python-install', 'include',
# 'python2.7', 'pyconfig.h'),
# join('private', 'include', 'python2.7/'))

# info('Removing some unwanted files')
# shprint(sh.rm, '-f', join('private', 'lib', 'libpython2.7.so'))
# shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig'))

# libdir = join(self.dist_dir, 'private', 'lib', 'python2.7')
# site_packages_dir = join(libdir, 'site-packages')
# with current_directory(libdir):
# removes = []
# for dirname, root, filenames in walk("."):
# for filename in filenames:
# for suffix in EXCLUDE_EXTS:
# if filename.endswith(suffix):
# removes.append(filename)
# shprint(sh.rm, '-f', *removes)

# info('Deleting some other stuff not used on android')
# # To quote the original distribute.sh, 'well...'
# shprint(sh.rm, '-rf', 'lib2to3')
# shprint(sh.rm, '-rf', 'idlelib')
# for filename in glob.glob('config/libpython*.a'):
# shprint(sh.rm, '-f', filename)
# shprint(sh.rm, '-rf', 'config/python.o')

# else: # Python *is* loaded from crystax
# ndk_dir = self.ctx.ndk_dir
# py_recipe = self.ctx.python_recipe
# python_dir = join(ndk_dir, 'sources', 'python',
# py_recipe.version, 'libs', arch.arch)
# shprint(sh.cp, '-r', join(python_dir,
# 'stdlib.zip'), crystax_python_dir)
# shprint(sh.cp, '-r', join(python_dir,
# 'modules'), crystax_python_dir)
# shprint(sh.cp, '-r', self.ctx.get_python_install_dir(),
# join(crystax_python_dir, 'site-packages'))

# info('Renaming .so files to reflect cross-compile')
# site_packages_dir = join(crystax_python_dir, "site-packages")
# find_ret = shprint(
# sh.find, site_packages_dir, '-iname', '*.so')
# filenames = find_ret.stdout.decode('utf-8').split('\n')[:-1]
# for filename in filenames:
# parts = filename.split('.')
# if len(parts) <= 2:
# continue
# shprint(sh.mv, filename, filename.split('.')[0] + '.so')
# site_packages_dir = join(abspath(curdir),
# site_packages_dir)
# if 'sqlite3' not in self.ctx.recipe_build_order:
# with open('blacklist.txt', 'a') as fileh:
# fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')

ndk_dir = self.ctx.ndk_dir
py_recipe = self.ctx.python_recipe
shprint(sh.cp, '-r', '/home/sandy/crystax_python', 'crystax_python')
shprint(sh.cp, '-r', self.ctx.get_python_install_dir(),
join(crystax_python_dir, 'site-packages'))

python3_build_dir = join(Recipe.get_recipe('python3', self.ctx).get_build_dir(arch.arch),
'Android', 'build',
'python3.7-android-{}-armv7'.format(self.ctx.ndk_target_api))
shprint(sh.cp, join(python3_build_dir, 'libpython3.7m.so'), 'libs/{}'.format(arch.arch))
shprint(sh.cp, join(python3_build_dir, 'libpython3.7m.so.1.0'), 'libs/{}'.format(arch.arch))

info('Renaming .so files to reflect cross-compile')
site_packages_dir = join(crystax_python_dir, "site-packages")
find_ret = shprint(
sh.find, site_packages_dir, '-iname', '*.so')
filenames = find_ret.stdout.decode('utf-8').split('\n')[:-1]
for filename in filenames:
parts = filename.split('.')
if len(parts) <= 2:
continue
shprint(sh.mv, filename, filename.split('.')[0] + '.so')
site_packages_dir = join(abspath(curdir),
site_packages_dir)

if 'sqlite3' not in self.ctx.recipe_build_order:
with open('blacklist.txt', 'a') as fileh:
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')

self.strip_libraries(arch)
self.fry_eggs(site_packages_dir)
# self.fry_eggs(site_packages_dir)
super(SDL2GradleBootstrap, self).run_distribute()


Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/bootstraps/sdl2/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ def make_package(args):

def parse_args(args=None):
global BLACKLIST_PATTERNS, WHITELIST_PATTERNS, PYTHON
default_android_api = 12
default_android_api = 21
import argparse
ap = argparse.ArgumentParser(description='''\
Package a Python application for Android.
Expand Down
1 change: 1 addition & 0 deletions pythonforandroid/bootstraps/sdl2/build/jni/Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

# APP_ABI := armeabi armeabi-v7a x86
APP_ABI := $(ARCH)
APP_PLATFORM := android-21
11 changes: 8 additions & 3 deletions pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
start.c

LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS)
# LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS)

LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/python3/$(ARCH)/python3/Include -I$(LOCAL_PATH)/../../../../other_builds/python3/$(ARCH)/python3/Android/build/python3.7-android-$(TARGET_ANDROID_API)-armv7 -L$(LOCAL_PATH)/../../../../other_builds/python3/$(ARCH)/python3/Android/build/python3.7-android-$(TARGET_ANDROID_API)-armv7


# LOCAL_CFLAGS += -I/home/sandy/.local/share/python-for-android/build/bootstrap_builds/sdl2_gradle-python3/jni/src/../../../../other_builds/python3/armeabi-v7a/python3/Android/build/python3.7-android-24-armv7

LOCAL_SHARED_LIBRARIES := SDL2 python_shared

LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS)
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS) -lpython3.7m

LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
LOCAL_LDFLAGS += $(APPLICATION_ADDITIONAL_LDFLAGS) -L$(LOCAL_PATH)/../../../../other_builds/python3/$(ARCH)/python3/Android/build/python3.7-android-$(TARGET_ANDROID_API)-armv7

include $(BUILD_SHARED_LIBRARY)

Expand Down
12 changes: 10 additions & 2 deletions pythonforandroid/bootstraps/sdl2/build/jni/src/start.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,16 @@ int main(int argc, char *argv[]) {
char crystax_python_dir[256];
snprintf(crystax_python_dir, 256,
"%s/crystax_python", getenv("ANDROID_UNPACK"));
char stdlib[256];
snprintf(stdlib, 256,
"%s/crystax_python/stdlib.zip", getenv("ANDROID_UNPACK"));
if (dir_exists(crystax_python_dir)) {
LOGP("crystax_python exists");
if (file_exists(stdlib)) {
LOGP("stdlib.zip exists");
} else {
LOGP("no stdlib.zip exists");
}
char paths[256];
snprintf(paths, 256,
"%s/stdlib.zip:%s/modules",
Expand All @@ -137,14 +145,14 @@ int main(int argc, char *argv[]) {
LOGP("crystax_python does not exist");
}

LOGP("Calling Py_Initialize");
Py_Initialize();
LOGP("Py_Initialize returned successfully");

#if PY_MAJOR_VERSION < 3
PySys_SetArgv(argc, argv);
#endif

LOGP("Initialized python");

/* ensure threads will work.
*/
LOGP("AND: Init threads");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected static ArrayList<String> getLibraries(File filesDir) {
addLibraryIfExists(libsList, "crypto.*", libsDir);
libsList.add("python2.7");
libsList.add("python3.5m");
libsList.add("python3.7m");
libsList.add("main");
return libsList;
}
Expand All @@ -66,8 +67,8 @@ public static void loadLibraries(File filesDir) {
// load, and it has failed, give a more
// general error
Log.v(TAG, "Library loading error: " + e.getMessage());
if (lib.startsWith("python3.6") && !foundPython) {
throw new java.lang.RuntimeException("Could not load any libpythonXXX.so");
if (lib.startsWith("python3.7m") && !foundPython) {
throw new java.lang.RuntimeException("Could not load libpython3.7m.so");
} else if (lib.startsWith("python")) {
continue;
} else {
Expand Down
2 changes: 2 additions & 0 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def ensure_dirs(self):
ensure_dir(join(self.build_dir, 'bootstrap_builds'))
ensure_dir(join(self.build_dir, 'other_builds'))

ndk_target_api = 21

@property
def android_api(self):
'''The Android API being targeted.'''
Expand Down
Loading