10000 Merge branch 'master' of github.com:kivy/python-for-android into feat… · cheaphunter/python-for-android@93cdb23 · GitHub
[go: up one dir, main page]

Skip to content

Commit 93cdb23

Browse files
committed
Merge branch 'master' of github.com:kivy/python-for-android into feature-hostpython-invoke
Conflicts: pythonforandroid/bootstraps/sdl2/__init__.py pythonforandroid/toolchain.py
2 parents 8789cb0 + 3faf827 commit 93cdb23

File tree

20 files changed

+761
-350
lines changed

20 files changed

+761
-350
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
.packages
1616
python_for_android.egg-info
1717
src
18+
/build/
19+
__pycache__/

doc/source/bootstraps.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Bootstraps
33
==========
44

5-
python-for-android (p4a) supports multiple *bootstraps*. These fulfil a
F438
5+
python-for-android (p4a) supports multiple *bootstraps*. These fulfill a
66
similar role to recipes, but instead of describing how to compile a
77
specific module they describe how a full Android project may be put
88
together from a combination of individual recipes and other
@@ -91,6 +91,6 @@ be clear. However, the :code:`run_distribute` method must do all the
9191
work of creating a build directory, copying recipes etc into it, and
9292
adding or removing any extra components as necessary.
9393

94-
If you'd like to creat a bootstrap, the best resource is to check the
94+
If you'd like to create a bootstrap, the best resource is to check the
9595
existing ones in the p4a source code. You can also :doc:`contact the
9696
developers <troubleshooting>` if you have problems or questions.

doc/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ python-for-android
44
python-for-android is an open source build tool to let you package
55
Python code into standalone android APKs that can be passed around,
66
installed, or uploaded to marketplaces such as the Play Store just
7-
like any other Androip app. This tool was originally developed for the
7+
like any other Android app. This tool was originally developed for the
88
`Kivy cross-platform graphical framework <http://kivy.org/#home>`_,
99
but now supports multiple bootstraps and can be easily extended to
1010
package other types of Python app for Android.

pythonforandroid/bootstraps/pygame/__init__.py

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, logger, info_main, which
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, info_main
22
from os.path import join, exists
33
from os import walk
44
import glob
@@ -19,6 +19,9 @@ def run_distribute(self):
1919
# self.name)
2020
src_path = join(self.bootstrap_dir, 'build')
2121

22+
# AND: Hardcoding armeabi - naughty!
23+
arch = ArchAndroid(self.ctx)
24+
2225
with current_directory(self.dist_dir):
2326

2427
info('Creating initial layout')
@@ -40,21 +43,14 @@ def run_distribute(self):
4043
info('Copying python distribution')
4144
hostpython = sh.Command(self.ctx.hostpython)
4245
# AND: This *doesn't* need to be in arm env?
43-
shprint(hostpython, '-OO', '-m', 'compileall', self.ctx.get_python_install_dir())
46+
shprint(hostpython, '-OO', '-m', 'compileall', self.ctx.get_python_install_dir(),
47+
_tail=10, _filterout="^Listing", _critical=True)
4448
if not exists('python-install'):
4549
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')
4650

47-
info('Copying libs')
48-
# AND: Hardcoding armeabi - naughty!
49-
shprint(sh.mkdir, '-p', join('libs', 'armeabi'))
50-
for lib in glob.glob(join(self.build_dir, 'libs', 'armeabi', '*')):
51-
shprint(sh.cp, '-a', lib, join('libs', 'armeabi'))
52-
for lib in glob.glob(join(self.ctx.get_libs_dir('armeabi'), '*')):
53-
shprint(sh.cp, '-a', lib, join('libs', 'armeabi'))
54-
55-
info('Copying java files')
56-
for filename in glob.glob(self.ctx.javaclass_dir):
57-
shprint(sh.cp, '-a', filename, 'src')
51+
self.distribute_libs(arch, [join(self.build_dir, 'libs', arch.arch), self.ctx.get_libs_dir(arch.arch)]);
52+
self.distribute_aars(arch)
53+
self.distribute_javaclasses(self.ctx.javaclass_dir)
5854

5955
info('Filling private directory')
6056
if not exists(join('private', 'lib')):
@@ -91,21 +87,7 @@ def run_distribute(self):
9187
shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')
9288

9389

94-
info('Stripping libraries')
95-
env = ArchAndroid(self.ctx).get_env()
96-
strip = which('arm-linux-androideabi-strip', env['PATH'])
97-
if strip is None:
98-
warning('Can\'t find strip in PATH...')
99-
strip = sh.Command(strip)
100-
filens = shprint(sh.find, join(self.dist_dir, 'private'), join(self.dist_dir, 'libs'),
101-
'-iname', '*.so', _env=env).stdout.decode('utf-8')
102-
logger.info('Stripping libraries in private dir')
103-
for filen in filens.split('\n'):
104-
try:
105-
strip(filen, _env=env)
106-
except sh.ErrorReturnCode_1:
107-
logger.debug('Failed to strip ' + 'filen')
108-
90+
self.strip_libraries(arch)
10991
super(PygameBootstrap, self).run_distribute()
11092

11193
bootstrap = PygameBootstrap()

pythonforandroid/bootstraps/pygame/build/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def select(fn):
183183
tf = tarfile.open(tfn, 'w:gz', format=tarfile.USTAR_FORMAT)
184184
dirs = []
185185
for fn, afn in files:
186-
print('%s: %s' % (tfn, fn))
186+
# print('%s: %s' % (tfn, fn))
187187
dn = dirname(afn)
188188
if dn not in dirs:
189189
# create every dirs first if not exist yet

pythonforandroid/bootstraps/pygame/build/src/org/renpy/android/AssetExtract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public boolean extractTar(String asset, String target) {
6060
break;
6161
}
6262

63-
Log.i("python", "extracting " + entry.getName());
63+
Log.v("python", "extracting " + entry.getName());
6464

6565
if (entry.isDirectory()) {
6666

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, logger, info_main, which
2-
from os.path import join, exists, getsize
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, info_main
2+
from os.path import join, exists
33
from os import walk
44
import glob
55
import sh
@@ -20,6 +20,9 @@ def run_distribute(self):
2020
with open('local.properties', 'w') as fileh:
2121
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
2222

23+
# AND: Hardcoding armeabi - naughty!
24+
arch = ArchAndroid(self.ctx)
25+
2326
with current_directory(self.dist_dir):
2427
info('Copying python distribution')
2528

@@ -31,19 +34,14 @@ def run_distribute(self):
3134
hostpython = sh.Command(self.ctx.hostpython)
3235
# AND: This *doesn't* need to be in arm env?
3336
shprint(hostpython, '-OO', '-m', 'compileall',
34-
self.ctx.get_python_install_dir())
37+
self.ctx.get_python_install_dir(),
38+
_tail=10, _filterout="^Listing", _critical=True)
3539
if not exists('python-install'):
3640
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')
3741

38-
info('Copying libs')
39-
# AND: Hardcoding armeabi - naughty!
40-
shprint(sh.mkdir, '-p', join('libs', 'armeabi'))
41-
for lib in glob.glob(join(self.ctx.get_libs_dir('armeabi'), '*')):
42-
shprint(sh.cp, '-a', lib, join('libs', 'armeabi'))
43-
44-
info('Copying java files')
45-
for filename in glob.glob(self.ctx.javaclass_dir):
46-
shprint(sh.cp, '-a', filename, 'src')
42+
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
43+
self.distribute_aars(arch)
44+
self.distribute_javaclasses(self.ctx.javaclass_dir)
4745

4846
info('Filling private directory')
4947
if not exists(join('private', 'lib')):
@@ -81,22 +79,7 @@ def run_distribute(self):
8179
# shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so')
8280
# shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')
8381

84-
85-
info('Stripping libraries')
86-
env = ArchAndroid(self.ctx).get_env()
87-
strip = which('arm-linux-androideabi-strip', env['PATH'])
88-
if strip is None:
89-
warning('Can\'t find strip in PATH...')
90-
strip = sh.Command(strip)
91-
filens = shprint(sh.find, join(self.dist_dir, 'private'), join(self.dist_dir, 'libs'),
92-
'-iname', '*.so', _env=env).stdout.decode('utf-8')
93-
logger.info('Stripping libraries in private dir')
94-
for filen in filens.split('\n'):
95-
try:
96-
if exists(filen) and getsize(filen):
97-
strip(filen, _env=env)
98-
except sh.ErrorReturnCode_1:
99-
logger.debug('Failed to strip ' + filen)
82+
self.strip_libraries(arch)
10083
super(SDL2Bootstrap, self).run_distribute()
10184

10285
bootstrap = SDL2Bootstrap()

pythonforandroid/bootstraps/sdl2/build/build.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def select(fn):
166166
tf = tarfile.open(tfn, 'w:gz', format=tarfile.USTAR_FORMAT)
167167
dirs = []
168168
for fn, afn in files:
169-
print('%s: %s' % (tfn, fn))
169+
# print('%s: %s' % (tfn, fn))
170170
dn = dirname(afn)
171171
if dn not in dirs:
172172
# create every dirs first if not exist yet
@@ -249,6 +249,10 @@ def make_package(args):
249249
default_icon = 'templates/kivy-icon.png'
250250
shutil.copy(args.icon or default_icon, 'res/drawable/icon.png')
251251

252+
default_presplash = 'templates/kivy-presplash.jpg'
253+
shutil.copy(args.presplash or default_presplash,
254+
'res/drawable/presplash.jpg')
255+
252256
versioned_name = (args.name.replace(' ', '').replace('\'', '') +
253257
'-' + args.version)
254258

@@ -324,6 +328,14 @@ def parse_args(args=None):
324328
help='A png file to use as the icon for the application.')
325329
ap.add_argument('--permission', dest='permissions', action='append',
326330
help='The permissions to give this app.')
331+
ap.add_argument('--meta-data', dest='meta_data', action='append',
332+
help='Custom key=value to add in application metadata')
333+
ap.add_argument('--presplash', dest='presplash',
334+
help=('A jpeg file to use as a screen while the '
335+
'application is loading.'))
336+
ap.add_argument('--wakelock', dest='wakelock', action='store_true',
337+
help=('Indicate if the application needs the device '
338+
'to stay on'))
327339

328340
if args is None:
329341
args = sys.argv[1:]
@@ -333,6 +345,9 @@ def parse_args(args=None):
333345
if args.permissions is None:
334346
args.permissions = []
335347

348+
if args.meta_data is None:
349+
args.meta_data = []
350+
336351
make_package(args)
337352

338353
if __name__ == "__main__":

pythonforandroid/bootstraps/sdl2/build/src/org/kivy/android/PythonActivity.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,34 @@
77
import java.io.FileWriter;
88
import java.io.File;
99

10+
import android.view.ViewGroup;
11+
import android.view.SurfaceView;
1012
import android.app.Activity;
1113
import android.util.Log;
1214
import android.widget.Toast;
1315
import android.os.Bundle;
16+
import android.os.PowerManager;
17+
import android.graphics.PixelFormat;
18+
import android.view.SurfaceHolder;
19+
import android.content.Context;
20+
import android.content.pm.PackageManager;
21+
import android.content.pm.ApplicationInfo;
1422

1523
import org.libsdl.app.SDLActivity;
1624

1725
import org.renpy.android.ResourceManager;
1826
import org.renpy.android.AssetExtract;
1927

28+
2029
public class PythonActivity extends SDLActivity {
2130
private static final String TAG = "PythonActivity";
2231

2332
public static PythonActivity mActivity = null;
2433

25-
private ResourceManager resourceManager;
26-
34+
private ResourceManager resourceManager = null;
35+
private Bundle mMetaData = null;
36+
private PowerManager.WakeLock mWakeLock = null;
37+
2738
@Override
2839
protected void onCreate(Bundle savedInstanceState) {
2940
Log.v(TAG, "My oncreate running");
@@ -48,6 +59,25 @@ protected void onCreate(Bundle savedInstanceState) {
4859

4960

5061
// nativeSetEnv("ANDROID_ARGUMENT", getFilesDir());
62+
63+
try {
64+
Log.v(TAG, "Access to our meta-data...");
65+
this.mMetaData = this.mActivity.getPackageManager().getApplicationInfo(
66+
this.mActivity.getPackageName(), PackageManager.GET_META_DATA).metaData;
67+
68+
PowerManager pm = (PowerManager) this.mActivity.getSystemService(Context.POWER_SERVICE);
69+
if ( this.mMetaData.getInt("wakelock") == 1 ) {
70+
this.mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Screen On");
71+
}
72+
if ( this.mMetaData.getInt("surface.transparent") != 0 ) {
73+
Log.v(TAG, "Surface will be transparent.");
74+
getSurface().setZOrderOnTop(true);
75+
getSurface().getHolder().setFormat(PixelFormat.TRANSPARENT);
76+
} else {
77+
Log.i(TAG, "Surface will NOT be transparent");
78+
}
79+
} catch (PackageManager.NameNotFoundException e) {
80+
}
5181
}
5282

5383
// This is just overrides the normal SDLActivity, which just loads
@@ -169,6 +199,13 @@ public void unpackData(final String resource, File target) {
169199
Log.w("python", e);
170200
}
171201
}
202+
}
203+
204+
public static ViewGroup getLayout() {
205+
return mLayout;
206+
}
172207

208+
public static SurfaceView getSurface() {
209+
return mSurface;
173210
}
174211
}

pythonforandroid/bootstraps/sdl2/build/src/org/renpy/android/AssetExtract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public boolean extractTar(String asset, String target) {
6060
break;
6161
}
6262

63-
Log.i("python", "extracting " + entry.getName());
63+
Log.v("python", "extracting " + entry.getName());
6464

6565
if (entry.isDirectory()) {
6666

0 commit comments

Comments
 (0)
0