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

kivy / python-for-android / 25435676503

06 May 2026 12:37PM UTC coverage: 62.876% (-1.0%) from 63.887%
25435676503

Pull #3278

github

web-flow
Merge 3c07c5446 into 3ab2fd669
Pull Request #3278: Handling system bars and Edge-to-Edge enforcement (android 15+)

1832 of 3180 branches covered (57.61%)

Branch coverage included in aggregate %.

5329 of 8209 relevant lines covered (64.92%)

5.18 hits per line

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

22.39
/pythonforandroid/recipes/tflite-runtime/__init__.py
1
from pythonforandroid.recipe import PythonRecipe, current_directory, \
8✔
2
    shprint, info_main, warning
3
from pythonforandroid.logger import error
8✔
4
from os.path import exists, join
8✔
5
import sh
8✔
6

7

8
class TFLiteRuntimeRecipe(PythonRecipe):
8✔
9
    ###############################################################
10
    #
11
    # tflite-runtime README:
12
    # https://github.com/Android-for-Python/c4k_tflite_example/blob/main/README.md
13
    #
14
    # Recipe build references:
15
    # https://developer.android.com/ndk/guides/cmake
16
    # https://developer.android.com/ndk/guides/cpu-arm-neon#cmake
17
    # https://www.tensorflow.org/lite/guide/build_cmake
18
    # https://www.tensorflow.org/lite/guide/build_cmake_arm
19
    #
20
    # Tested using cmake 3.16.3 probably requires cmake >= 3.13
21
    #
22
    # THIS RECIPE DOES NOT BUILD x86_64, USE X86 FOR AN EMULATOR
23
    #
24
    ###############################################################
25

26
    version = '2.8.0'
8✔
27
    url = 'https://github.com/tensorflow/tensorflow/archive/refs/tags/v{version}.zip'
8✔
28
    depends = ['numpy']
8✔
29
    hostpython_prerequisites = ['pybind11==2.11.1']
8✔
30
    patches = ['CMakeLists.patch', 'build_with_cmake.patch']
8✔
31
    site_packages_name = 'tflite-runtime'
8✔
32
    call_hostpython_via_targetpython = False
8✔
33

34
    def should_build(self, arch):
8✔
35
        name = self.folder_name.replace('-', '_')
×
36

37
        if self.ctx.has_package(name, arch):
×
38
            info_main('Python package already exists in site-packages')
×
39
            return False
×
40
        info_main('{} apparently isn\'t already in site-packages'.format(name))
×
41
        return True
×
42

43
    def build_arch(self, arch):
8✔
44
        if arch.arch == 'x86_64':
×
45
            warning("******** tflite-runtime x86_64 will not be built *******")
×
46
            warning("Expect one of these app run time error messages:")
×
47
            warning("ModuleNotFoundError: No module named 'tensorflow'")
×
48
            warning("ModuleNotFoundError: No module named 'tflite_runtime'")
×
49
            warning("Use x86 not x86_64")
×
50
            return
×
51

52
        env = self.get_recipe_env(arch)
×
53
        self.install_hostpython_prerequisites()
×
54

55
        # Directories
56
        root_dir = self.get_build_dir(arch.arch)
×
57
        script_dir = join(root_dir,
×
58
                          'tensorflow', 'lite', 'tools', 'pip_package')
59
        build_dir = join(script_dir, 'gen', 'tflite_pip', 'python3')
×
60

61
        # Includes
62
        python_include_dir = self.ctx.python_recipe.include_root(arch.arch)
×
63
        pybind11_include_dir = sh.Command(self.real_hostpython_location)(
×
64
            '-c', 'import pybind11; print(pybind11.get_include())'
65
        ).strip()
66
        numpy_include_dir = join(self.ctx.get_site_packages_dir(arch),
×
67
                                 'numpy', '_core', 'include')
68
        if not exists(numpy_include_dir):
×
69
            numpy_include_dir = join(self.ctx.get_site_packages_dir(arch),
×
70
                                     'numpy', 'core', 'include')
71
        includes = ' -I' + python_include_dir + \
×
72
                   ' -I' + numpy_include_dir + \
73
                   ' -I' + pybind11_include_dir
74

75
        # Scripts
76
        build_script = join(script_dir, 'build_pip_package_with_cmake.sh')
×
77
        toolchain = join(self.ctx.ndk_dir,
×
78
                         'build', 'cmake', 'android.toolchain.cmake')
79

80
        # Build
81
        ########
82
        with current_directory(root_dir):
×
83
            env.update({
×
84
                'TENSORFLOW_TARGET': 'android',
85
                'CMAKE_TOOLCHAIN_FILE': toolchain,
86
                'ANDROID_PLATFORM': str(self.ctx.ndk_api),
87
                'ANDROID_ABI': arch.arch,
88
                'WRAPPER_INCLUDES': includes,
89
                'CMAKE_SHARED_LINKER_FLAGS': env['LDFLAGS'],
90
                'CMAKE_POLICY_VERSION_MINIMUM': '3.5',
91
            })
92

93
            try:
×
94
                info_main('tflite-runtime is building...')
×
95
                info_main('Expect this to take at least 5 minutes...')
×
96
                cmd = sh.Command(build_script)
×
97
                cmd(_env=env)
×
98
            except sh.ErrorReturnCode as e:
×
99
                error(str(e.stderr))
×
100
                exit(1)
×
101

102
        # Install
103
        ##########
104
        info_main('Installing tflite-runtime into site-packages')
×
105
        with current_directory(build_dir):
×
106
            hostpython = sh.Command(self.hostpython_location)
×
107
            install_dir = self.ctx.get_python_install_dir(arch.arch)
×
108
            env['PACKAGE_VERSION'] = self.version
×
109
            shprint(hostpython, 'setup.py', 'install', '-O2',
×
110
                    '--root={}'.format(install_dir),
111
                    '--install-lib=.',
112
                    _env=env)
113

114

115
recipe = TFLiteRuntimeRecipe()
8✔
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

© 2026 Coveralls, Inc