3

I want to include a c++-library in my kivy python app. It is possible to automatically do that with swig and distutils, which effectively generates a .pyd python library out of the c++ code. On windows that works without any problems: I included the .pyd file in my Kivy app and everything runs, but I want to run the program on mobile devices as well.

So my problem is how I can generate a python library which is compatible with android (arm) and includes the c++-code I need.

I already asked a different question about how I can cross-compile python code for arm on windows x86_64. There someone recommended Chaquopy. That seems to work, but of course only with python as source code, not with c++.

For the library creation process with swig and distutils I created a 'setup.py' which takes the output from swig and builds the .pyd library. Is it possible to modify that to compile for arm?

#!/usr/bin/env python

"""
setup.py file for SWIG
"""

from distutils.core import setup, Extension


example_module = Extension('_HelloCpp',
                           sources=['HelloCpp_wrap.cxx', 'HelloCpp.cpp'],
                           extra_compile_args = ["-std:c++17"]
                           )

setup (name = 'HelloCpp',
       version = '0.1',
       author      = "simonsays",
       description = """Simple swig test with HelloCpp""",
       ext_modules = [example_module],
       py_modules = ["HelloCpp"],
       )

I also stumbled over this Github repository: Virtual Environments for Cross-Compiling Python Extension Modules. Do I need that to compile Python for Android or is there a different approach?

mhsmith
  • 6,675
  • 3
  • 41
  • 58
simonsays
  • 81
  • 5

1 Answers1

0

To include a C++ library in an Android Kivy app, you'll need to define a compilation recipe. For details, see the python-for-android documentation, and the list of existing recipes.

mhsmith
  • 6,675
  • 3
  • 41
  • 58