simonsays
simonsays

Reputation: 101

Creating a Python library for use in Android

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.

Upvotes: 2

Views: 1094

Answers (1)

Saurabh
Saurabh

Reputation: 184

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/

Upvotes: 2

Related Questions