2

My Kivy app uses a python library file. On Windows it works without any problems with the .pyd file I created, but I obviously can not use the same library file on Android (because a .pyd file is essentially a .dll)

Is it possible to "cross-compile" my python code into a .so-library for Arm-Android on Windows/Linux?

I 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?

Edit: To specify my problem a bit more, I originally wanted to include a c++-library in the python app. It is possible to automatically do that with swig and distutils, which generates a .pyd python library out of the c++ code. As described above that only worked on windows so far. @S recommended Chaquopy, which seems to work partially: It works for using python on android, but I am not sure, whether it works in combination with c++ and swig. To not further derail this question, I have created a new question which focusses on the c++-aspect.

simonsays
  • 81
  • 5

1 Answers1

2

you can use the Chaquopy plugin for Android Studio. Chaquopy allows you to run Python code on Android, and it supports compiling Python native extensions as .so files for Android ARM

Place your Python code and any dependencies in the src/main/python directory

official Chaquopy documentation: https://chaquo.com/chaquopy/doc/current/

Saurabh
  • 164
  • 2
  • @S thank you for your reply, It worked! My problem is, that i couldn't find a way to combine that with the other part of my problem (which I probably should have mentioned earlier...) I edited my question, maybe you know something about that too? – simonsays Apr 21 '23 at 13:44
  • Instructions for compiling extension modules for Chaquopy are [here](https://github.com/chaquo/chaquopy/blob/master/server/pypi/README.md). The build tool supports both SWIG and C++. However, if your app already uses Kivy, then it's probably easier to stay with their build tool: I'll post the details of that in [your other question](https://stackoverflow.com/questions/76073747). – mhsmith May 18 '23 at 08:33