• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kivy / python-for-android / 17778298507

16 Sep 2025 08:33PM UTC coverage: 59.174% (-0.04%) from 59.214%
17778298507

push

github

web-flow
Merge pull request #3208 from T-Dynamos/android-fix

`android`: shift to PPR

1060 of 2385 branches covered (44.44%)

Branch coverage included in aggregate %.

4 of 5 new or added lines in 1 file covered. (80.0%)

4955 of 7780 relevant lines covered (63.69%)

2.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

24.56
/pythonforandroid/recipes/android/__init__.py
1
from pythonforandroid.recipe import PyProjectRecipe, IncludedFilesBehaviour
4✔
2
from pythonforandroid.util import current_directory
4✔
3
from pythonforandroid import logger
4✔
4

5
from os.path import join
4✔
6

7

8
class AndroidRecipe(IncludedFilesBehaviour, PyProjectRecipe):
4✔
9
    # name = 'android'
10
    version = None
4✔
11
    url = None
4✔
12

13
    src_filename = 'src'
4✔
14

15
    depends = [('sdl3', 'sdl2', 'genericndkbuild'), 'pyjnius']
4✔
16
    hostpython_prerequisites = ["Cython>=0.29,<3.1"]
4✔
17

18
    config_env = {}
4✔
19

20
    def get_recipe_env(self, arch, **kwargs):
4✔
NEW
21
        env = super().get_recipe_env(arch, **kwargs)
×
22
        env.update(self.config_env)
×
23
        return env
×
24

25
    def prebuild_arch(self, arch):
4✔
26
        super().prebuild_arch(arch)
×
27
        ctx_bootstrap = self.ctx.bootstrap.name
×
28

29
        # define macros for Cython, C, Python
30
        tpxi = 'DEF {} = {}\n'
×
31
        th = '#define {} {}\n'
×
32
        tpy = '{} = {}\n'
×
33

34
        # make sure bootstrap name is in unicode
35
        if isinstance(ctx_bootstrap, bytes):
×
36
            ctx_bootstrap = ctx_bootstrap.decode('utf-8')
×
37
        bootstrap = bootstrap_name = ctx_bootstrap
×
38
        if bootstrap_name in ["sdl2", "sdl3", "webview", "service_only", "service_library", "qt"]:
×
39
            java_ns = u'org.kivy.android'
×
40
            jni_ns = u'org/kivy/android'
×
41
        else:
42
            logger.error((
×
43
                'unsupported bootstrap for android recipe: {}'
44
                ''.format(bootstrap_name)
45
            ))
46
            exit(1)
×
47

48
        config = {
×
49
            'BOOTSTRAP': bootstrap,
50
            'IS_SDL2': int(bootstrap_name == "sdl2"),
51
            'IS_SDL3': int(bootstrap_name == "sdl3"),
52
            'PY2': 0,
53
            'ANDROID_LIBS_DIR': "{}:{}".format(
54
                self.ctx.get_libs_dir(arch.arch),
55
                join(self.ctx.bootstrap.build_dir, 'obj', 'local', arch.arch)
56
            ),
57
            'JAVA_NAMESPACE': java_ns,
58
            'JNI_NAMESPACE': jni_ns,
59
            'ACTIVITY_CLASS_NAME': self.ctx.activity_class_name,
60
            'ACTIVITY_CLASS_NAMESPACE': self.ctx.activity_class_name.replace('.', '/'),
61
            'SERVICE_CLASS_NAME': self.ctx.service_class_name,
62
        }
63

64
        # create config files for Cython, C and Python
65
        with (
×
66
                current_directory(self.get_build_dir(arch.arch))), (
67
                open(join('android', 'config.pxi'), 'w')) as fpxi, (
68
                open(join('android', 'config.h'), 'w')) as fh, (
69
                open(join('android', 'config.py'), 'w')) as fpy:
70

71
            for key, value in config.items():
×
72
                fpxi.write(tpxi.format(key, repr(value)))
×
73
                fpy.write(tpy.format(key, repr(value)))
×
74

75
                fh.write(th.format(
×
76
                    key,
77
                    value if isinstance(value, int) else '"{}"'.format(value)
78
                ))
79
                self.config_env[key] = str(value)
×
80

81
            if bootstrap_name == "sdl2":
×
82
                fh.write('JNIEnv *SDL_AndroidGetJNIEnv(void);\n')
×
83
                fh.write(
×
84
                    '#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\n'
85
                )
86
            elif bootstrap_name == "sdl3":
×
87
                fh.write('JNIEnv *SDL_GetAndroidJNIEnv(void);\n')
×
88
                fh.write(
×
89
                    '#define SDL_ANDROID_GetJNIEnv SDL_GetAndroidJNIEnv\n'
90
                )
91
            else:
92
                fh.write('JNIEnv *WebView_AndroidGetJNIEnv(void);\n')
×
93
                fh.write(
×
94
                    '#define SDL_ANDROID_GetJNIEnv WebView_AndroidGetJNIEnv\n'
95
                )
96

97

98
recipe = AndroidRecipe()
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc