Skip to content

Commit 4ea920f

Browse files
committed
Merge pull request #728 from inclement/webview_bootstrap
Add webview bootstrap
2 parents 54afc33 + 64ba407 commit 4ea920f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4700
-3
lines changed

doc/source/buildoptions.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ yet have one.
9393
features of the Pygame one. It is under active development to fix
9494
these omissions.
9595

96+
webview
97+
~~~~~~~
98+
99+
You can use this with ``--bootstrap=webview``, or simply include the
100+
``webviewjni`` recipe in your ``--requirements``.
101+
102+
The webview bootstrap gui is, per the name, a WebView displaying a
103+
webpage, but this page is hosted on the device via a Python
104+
webserver. For instance, your Python code can start a Flask
105+
application, and your app will display and allow the user to navigate
106+
this website.
107+
108+
This bootstrap will automatically try to load a website on port 5000
109+
(the default for Flask), or you can specify a different option with
110+
the `--port` command line option. If the webserver is not immediately
111+
present (e.g. during the short Python loading time when first
112+
started), it will instead display a loading screen until the server is
113+
ready.
114+
115+
96116
pygame
97117
~~~~~~
98118

pythonforandroid/bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def run_distribute(self):
111111
json.dump({'dist_name': self.ctx.dist_name,
112112
'bootstrap': self.ctx.bootstrap.name,
113113
'archs': [arch.arch for arch in self.ctx.archs],
114-
'recipes': self.ctx.recipe_build_order},
114+
'recipes': self.ctx.recipe_build_order + self.ctx.python_modules},
115115
fileh)
116116

117117
@classmethod
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchARM, info_main
2+
from os.path import join, exists, curdir, abspath
3+
from os import walk
4+
import glob
5+
import sh
6+
7+
class WebViewBootstrap(Bootstrap):
8+
name = 'webview'
9+
10+
recipe_depends = ['webviewjni', ('python2', 'python3crystax')]
11+
12+
def run_distribute(self):
13+
info_main('# Creating Android project from build and {} bootstrap'.format(
14+
self.name))
15+
16+
shprint(sh.rm, '-rf', self.dist_dir)
17+
shprint(sh.cp, '-r', self.build_dir, self.dist_dir)
18+
with current_directory(self.dist_dir):
19+
with open('local.properties', 'w') as fileh:
20+
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
21+
22+
arch = self.ctx.archs[0]
23+
if len(self.ctx.archs) > 1:
24+
raise ValueError('built for more than one arch, but bootstrap cannot handle that yet')
25+
info('Bootstrap running with arch {}'.format(arch))
26+
27+
with current_directory(self.dist_dir):
28+
info('Copying python distribution')
29+
30+
if not exists('private') and not self.ctx.python_recipe.from_crystax:
31+
shprint(sh.mkdir, 'private')
32+
if not exists('crystax_python') and self.ctx.python_recipe.from_crystax:
33+
shprint(sh.mkdir, 'crystax_python')
34+
shprint(sh.mkdir, 'crystax_python/crystax_python')
35+
if not exists('assets'):
36+
shprint(sh.mkdir, 'assets')
37+
38+
hostpython = sh.Command(self.ctx.hostpython)
39+
if not self.ctx.python_recipe.from_crystax:
40+
try:
41+
shprint(hostpython, '-OO', '-m', 'compileall',
42+
self.ctx.get_python_install_dir(),
43+
_tail=10, _filterout="^Listing")
44+
except sh.ErrorReturnCode:
45+
pass
46+
if not exists('python-install'):
47+
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')
48+
49+
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
50+
self.distribute_aars(arch)
51+
self.distribute_javaclasses(self.ctx.javaclass_dir)
52+
53+
if not self.ctx.python_recipe.from_crystax:
54+
info('Filling private directory')
55+
if not exists(join('private', 'lib')):
56+
info('private/lib does not exist, making')
57+
shprint(sh.cp, '-a', join('python-install', 'lib'), 'private')
58+
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))
59+
60+
# AND: Copylibs stuff should go here
61+
if exists(join('libs', arch.arch, 'libpymodules.so')):
62+
shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/')
63+
shprint(sh.cp, join('python-install', 'include' , 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))
64+
65+
info('Removing some unwanted files')
66+
shprint(sh.rm, '-f', join('private', 'lib', 'libpython2.7.so'))
67+
shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig'))
68+
69+
libdir = join(self.dist_dir, 'private', 'lib', 'python2.7')
70+
site_packages_dir = join(libdir, 'site-packages')
71+
with current_directory(libdir):
72+
# shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.')))
73+
removes = []
74+
for dirname, something, filens in walk('.'):
75+
for filename in filens:
76+
for suffix in ('py', 'pyc', 'so.o', 'so.a', 'so.libs'):
77+
if filename.endswith(suffix):
78+
removes.append(filename)
79+
shprint(sh.rm, '-f', *removes)
80+
81+
info('Deleting some other stuff not used on android')
82+
# To quote the original distribute.sh, 'well...'
83+
# shprint(sh.rm, '-rf', 'ctypes')
84+
shprint(sh.rm, '-rf', 'lib2to3')
85+
shprint(sh.rm, '-rf', 'idlelib')
86+
for filename in glob.glob('config/libpython*.a'):
87+
shprint(sh.rm, '-f', filename)
88+
shprint(sh.rm, '-rf', 'config/python.o')
89+
# shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so')
90+
# shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')
91+
92+
else: # Python *is* loaded from crystax
93+
ndk_dir = self.ctx.ndk_dir
94+
py_recipe = self.ctx.python_recipe
95+
python_dir = join(ndk_dir, 'sources', 'python', py_recipe.version,
96+
'libs', arch.arch)
97+
98+
shprint(sh.cp, '-r', join(python_dir, 'stdlib.zip'), 'crystax_python/crystax_python')
99+
shprint(sh.cp, '-r', join(python_dir, 'modules'), 'crystax_python/crystax_python')
100+
shprint(sh.cp, '-r', self.ctx.get_python_install_dir(), 'crystax_python/crystax_python/site-packages')
101+
102+
info('Renaming .so files to reflect cross-compile')
103+
site_packages_dir = 'crystax_python/crystax_python/site-packages'
104+
filens = shprint(sh.find, site_packages_dir, '-iname', '*.so').stdout.decode(
105+
'utf-8').split('\n')[:-1]
106+
for filen in filens:
107+
parts = filen.split('.')
108+
if len(parts) <= 2:
109+
continue
110+
shprint(sh.mv, filen, filen.split('.')[0] + '.so')
111+
site_packages_dir = join(abspath(curdir),
112+
site_packages_dir)
113+
114+
115+
self.strip_libraries(arch)
116+
self.fry_eggs(site_packages_dir)
117+
super(WebViewBootstrap, self).run_distribute()
118+
119+
bootstrap = WebViewBootstrap()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Replace org.libsdl.app with the identifier of your game below, e.g.
3+
com.gamemaker.game
4+
-->
5+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
6+
package="org.kivy.android"
7+
android:versionCode="1"
8+
android:versionName="1.0"
9+
android:installLocation="auto">
10+
11+
<!-- Android 2.3.3 -->
12+
<uses-sdk android:minSdkVersion="12" android:targetSdkVersion="12" />
13+
14+
<!-- OpenGL ES 2.0 -->
15+
<uses-feature android:glEsVersion="0x00020000" />
16+
17+
<!-- Allow writing to external storage -->
18+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
19+
20+
<!-- Create a Java class extending SDLActivity and place it in a
21+
directory under src matching the package, e.g.
22+
src/com/gamemaker/game/MyGame.java
23+
24+
then replace "SDLActivity" with the name of your class (e.g. "MyGame")
25+
in the XML below.
26+
27+
An example Java class can be found in README-android.txt
28+
-->
29+
<application android:label="@string/app_name"
30+
android:icon="@drawable/icon"
31+
android:allowBackup="true"
32+
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
33+
android:hardwareAccelerated="true" >
34+
<activity android:name="org.kivy.android.PythonActivity"
35+
android:label="@string/app_name"
36+
android:configChanges="keyboardHidden|orientation"
37+
>
38+
<intent-filter>
39+
<action android:name="android.intent.action.MAIN" />
40+
<category android:name="android.intent.category.LAUNCHER" />
41+
</intent-filter>
42+
</activity>
43+
</application>
44+
45+
</manifest>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This file is used to override default values used by the Ant build system.
2+
#
3+
# This file must be checked into Version Control Systems, as it is
4+
# integral to the build system of your project.
5+
6+
# This file is only used by the Ant script.
7+
8+
# You can use this to override default values such as
9+
# 'source.dir' for the location of your java source folder and
10+
# 'out.dir' for the location of your output folder.
11+
12+
# You can also use it define how the release builds are signed by declaring
13+
# the following properties:
14+
# 'key.store' for the location of your keystore and
15+
# 'key.alias' for the name of the key to use.
16+
# The password will be asked during the build when you use the 'release' target.
17+
18+
source.absolute.dir = tmp-src
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# prevent user to include invalid extensions
2+
*.apk
3+
*.pxd
4+
5+
# eggs
6+
*.egg-info
7+
8+
# unit test
9+
unittest/*
10+
11+
# python config
12+
config/makesetup
13+
14+
# unused kivy files (platform specific)
15+
kivy/input/providers/wm_*
16+
kivy/input/providers/mactouch*
17+
kivy/input/providers/probesysfs*
18+
kivy/input/providers/mtdev*
19+
kivy/input/providers/hidinput*
20+
kivy/core/camera/camera_videocapture*
21+
kivy/core/spelling/*osx*
22+
kivy/core/video/video_pyglet*
23+
kivy/tools
24+
kivy/tests/*
25+
kivy/*/*.h
26+
kivy/*/*.pxi
27+
28+
# unused encodings
29+
lib-dynload/*codec*
30+
encodings/cp*.pyo
31+
encodings/tis*
32+
encodings/shift*
33+
encodings/bz2*
34+
encodings/iso*
35+
encodings/undefined*
36+
encodings/johab*
37+
encodings/p*
38+
encodings/m*
39+
encodings/euc*
40+
encodings/k*
41+
encodings/unicode_internal*
42+
encodings/quo*
43+
encodings/gb*
44+
encodings/big5*
45+
encodings/hp*
46+
encodings/hz*
47+
48+
# unused python modules
49+
bsddb/*
50+
wsgiref/*
51+
hotshot/*
52+
pydoc_data/*
53+
tty.pyo
54+
anydbm.pyo
55+
nturl2path.pyo
56+
LICENCE.txt
57+
macurl2path.pyo
58+
dummy_threading.pyo
59+
audiodev.pyo
60+
antigravity.pyo
61+
dumbdbm.pyo
62+
sndhdr.pyo
63+
__phello__.foo.pyo
64+
sunaudio.pyo
65+
os2emxpath.pyo
66+
multiprocessing/dummy*
67+
68+
# unused binaries python modules
69+
lib-dynload/termios.so
70+
lib-dynload/_lsprof.so
71+
lib-dynload/*audioop.so
72+
lib-dynload/mmap.so
73+
lib-dynload/_hotshot.so
74+
lib-dynload/_heapq.so
75+
lib-dynload/_json.so
76+
lib-dynload/grp.so
77+
lib-dynload/resource.so
78+
lib-dynload/pyexpat.so
79+
lib-dynload/_ctypes_test.so
80+
lib-dynload/_testcapi.so
81+
82+
# odd files
83+
plat-linux3/regen
84+
85+
#>sqlite3
86+
# conditionnal include depending if some recipes are included or not.
87+
sqlite3/*
88+
lib-dynload/_sqlite3.so
89+
#<sqlite3
90+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file is used to override default values used by the Ant build system.
2+
#
3+
# This file must be checked in Version Control Systems, as it is
4+
# integral to the build system of your project.
5+
6+
# This file is only used by the Ant script.
7+
8+
# You can use this to override default values such as
9+
# 'source.dir' for the location of your java source folder and
10+
# 'out.dir' for the location of your output folder.
11+
12+
# You can also use it define how the release builds are signed by declaring
13+
# the following properties:
14+
# 'key.store' for the location of your keystore and
15+
# 'key.alias' for the name of the key to use.
16+
# The password will be asked during the build when you use the 'release' target.
17+
18+
key.store=${env.P4A_RELEASE_KEYSTORE}
19+
key.alias=${env.P4A_RELEASE_KEYALIAS}
20+
key.store.password=${env.P4A_RELEASE_KEYSTORE_PASSWD}
21+
key.alias.password=${env.P4A_RELEASE_KEYALIAS_PASSWD}

0 commit comments

Comments
 (0)