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

kivy / python-for-android / 14999495895

13 May 2025 02:38PM UTC coverage: 58.724% (-0.5%) from 59.204%
14999495895

Pull #3136

github

web-flow
Merge 55a9af12f into 40993e323
Pull Request #3136: scipy: update to v1.15.2

1059 of 2408 branches covered (43.98%)

Branch coverage included in aggregate %.

73 of 221 new or added lines in 9 files covered. (33.03%)

4 existing lines in 3 files now uncovered.

4979 of 7874 relevant lines covered (63.23%)

2.52 hits per line

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

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

7

8
class TFLiteRuntimeRecipe(PythonRecipe):
4✔
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'
4✔
27
    url = 'https://github.com/tensorflow/tensorflow/archive/refs/tags/v{version}.zip'
4✔
28
    depends = ['pybind11', 'numpy']
4✔
29
    patches = ['CMakeLists.patch', 'build_with_cmake.patch']
4✔
30
    site_packages_name = 'tflite-runtime'
4✔
31
    call_hostpython_via_targetpython = False
4✔
32

33
    def should_build(self, arch):
4✔
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):
4✔
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')
65
        includes = ' -I' + python_include_dir + \
×
66
                   ' -I' + numpy_include_dir + \
67
                   ' -I' + pybind11_include_dir
68

69
        # Scripts
70
        build_script = join(script_dir, 'build_pip_package_with_cmake.sh')
×
71
        toolchain = join(self.ctx.ndk_dir,
×
72
                         'build', 'cmake', 'android.toolchain.cmake')
73

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

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

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

107

108
recipe = TFLiteRuntimeRecipe()
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

© 2026 Coveralls, Inc