1
+ from __future__ import unicode_literals
1
2
from pythonforandroid .recipe import CythonRecipe , IncludedFilesBehaviour
2
3
from pythonforandroid .util import current_directory
3
4
from pythonforandroid .patching import will_build
4
5
from pythonforandroid import logger
5
6
6
7
from os .path import join
7
- from sys import version_info
8
8
9
9
10
10
class AndroidRecipe (IncludedFilesBehaviour , CythonRecipe ):
@@ -26,27 +26,35 @@ def get_recipe_env(self, arch):
26
26
27
27
def prebuild_arch (self , arch ):
28
28
super (AndroidRecipe , self ).prebuild_arch (arch )
29
+ ctx_bootstrap = self .ctx .bootstrap .name
29
30
31
+ # define macros for Cython, C, Python
30
32
tpxi = 'DEF {} = {}\n '
31
33
th = '#define {} {}\n '
32
34
tpy = '{} = {}\n '
33
35
34
- bootstrap = self .ctx .bootstrap .name
35
- bootstrap = bootstrap_name = bootstrap if version_info >= (3 , ) else bootstrap .decode ('utf-8' )
36
+ # make sure bootstrap name is in unicode
37
+ if isinstance (ctx_bootstrap , bytes ):
38
+ ctx_bootstrap = ctx_bootstrap .decode ('utf-8' )
39
+ bootstrap = bootstrap_name = ctx_bootstrap
40
+
36
41
is_sdl2 = bootstrap_name in ('sdl2' , 'sdl2python3' , 'sdl2_gradle' )
37
42
is_pygame = bootstrap_name in ('pygame' ,)
38
43
is_webview = bootstrap_name in ('webview' ,)
39
44
40
45
if is_sdl2 or is_webview :
41
46
if is_sdl2 :
42
47
bootstrap = 'sdl2'
43
- java_ns = u 'org.kivy.android'
44
- jni_ns = u 'org/kivy/android'
48
+ java_ns = 'org.kivy.android'
49
+ jni_ns = 'org/kivy/android'
45
50
elif is_pygame :
46
- java_ns = 'org.renpy.android'
47
- jni_ns = 'org/renpy/android'
51
+ java_ns = b 'org.renpy.android'
52
+ jni_ns = b 'org/renpy/android'
48
53
else :
49
- logger .error ('unsupported bootstrap for android recipe: {}' .format (bootstrap_name ))
54
+ logger .error ((
55
+ 'unsupported bootstrap for android recipe: {}'
56
+ '' .format (bootstrap_name )
57
+ ))
50
58
exit (1 )
51
59
52
60
config = {
@@ -58,22 +66,28 @@ def prebuild_arch(self, arch):
58
66
'JNI_NAMESPACE' : jni_ns ,
59
67
}
60
68
69
+ # create config files for Cython, C and Python
61
70
with (
62
71
current_directory (self .get_build_dir (arch .arch ))), (
63
72
open (join ('android' , 'config.pxi' ), 'w' )) as fpxi , (
64
73
open (join ('android' , 'config.h' ), 'w' )) as fh , (
65
74
open (join ('android' , 'config.py' ), 'w' )) as fpy :
75
+
66
76
for key , value in config .items ():
67
77
fpxi .write (tpxi .format (key , repr (value )))
68
78
fpy .write (tpy .format (key , repr (value )))
69
- fh .write (th .format (key ,
70
- value if isinstance (value , int )
71
- else '"{}"' .format (value )))
79
+
80
+ fh .write (th .format (
81
+ key ,
82
+ value if isinstance (value , int ) else '"{}"' .format (value )
83
+ ))
72
84
self .config_env [key ] = str (value )
73
85
74
86
if is_sdl2 :
75
87
fh .write ('JNIEnv *SDL_AndroidGetJNIEnv(void);\n ' )
76
- fh .write ('#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\n ' )
88
+ fh .write (
89
+ '#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\n '
90
+ )
77
91
elif is_pygame :
78
92
fh .write ('JNIEnv *SDL_ANDROID_GetJNIEnv(void);\n ' )
79
93
0 commit comments