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

kivy / python-for-android / 25143943689

30 Apr 2026 02:17AM UTC coverage: 62.91% (-0.02%) from 62.932%
25143943689

Pull #3310

github

web-flow
Merge f93e9553e into 869c74bba
Pull Request #3310: Fix tflite-runtime numpy include path

1832 of 3177 branches covered (57.66%)

Branch coverage included in aggregate %.

1 of 3 new or added lines in 1 file covered. (33.33%)

1 existing line in 1 file now uncovered.

5329 of 8206 relevant lines covered (64.94%)

5.18 hits per line

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

21.21
/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 = ['pybind11', 'numpy']
8✔
29
    patches = ['CMakeLists.patch', 'build_with_cmake.patch']
8✔
30
    site_packages_name = 'tflite-runtime'
8✔
31
    call_hostpython_via_targetpython = False
8✔
32

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

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

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

51
        env = self.get_recipe_env(arch)
×
52

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

59
        # Includes
60
        python_include_dir = self.ctx.python_recipe.include_root(arch.arch)
×
61
        pybind11_recipe = self.get_recipe('pybind11', self.ctx)
×
62
        pybind11_include_dir = pybind11_recipe.get_include_dir(arch)
×
63
        numpy_include_dir = join(self.ctx.get_site_packages_dir(arch),
×
64
                                 'numpy', '_core', 'include')
NEW
65
        if not exists(numpy_include_dir):
×
NEW
66
            numpy_include_dir = join(self.ctx.get_site_packages_dir(arch),
×
67
                                     'numpy', 'core', 'include')
UNCOV
68
        includes = ' -I' + python_include_dir + \
×
69
                   ' -I' + numpy_include_dir + \
70
                   ' -I' + pybind11_include_dir
71

72
        # Scripts
73
        build_script = join(script_dir, 'build_pip_package_with_cmake.sh')
×
74
        toolchain = join(self.ctx.ndk_dir,
×
75
                         'build', 'cmake', 'android.toolchain.cmake')
76

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

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

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

110

111
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