First, I am sorry if this is a duplicate question but I have spent many hours before writing here looking for an answer and could not find any (that would work at least).
I want to (ideally) compile a python (3.6/7) script into an android app. I need to use external libraries in my code, namely matplotlib and numpy.
I have Kivy Launcher in my android device and can launch normal ("pure") Kivy scripts no problem, and they work fine. My code including matplotlib (see below), however, immediately crashes as I believe the module is not included into the Kivy Launcher.
As for trying to compile an apk, I have downloaded the VM from https://kivy.org/#download with a preinstalled and pre-configured Buildozer + python-for-android. Using it I could create .apk files which would install and run fine as long as they did not include external modules. I tried however to set matplotlib as one of the requirements in the buildozer.spec, and the compilation fails with a:
Command failed: ./distribute.sh -m "kivy matplotlib" -d "myapp"
At this point, I can run my code using matplotlib as a script in the Pydroid 3 app, where I could install my modules normally through pip (kivy, matplotlib, etc.). As for the kivy-matplotlib interface, I am using the matplotlib flower in the kivy-garden module which I just packaged locally with my code by running
garden install --app matplotlib
inside the script directory before exporting my code to the android device.
Is there any way to run this as a native app or at the very least through the Kivy Launcher? I have read that so far buildozer does not support matplotlib, but it was from an un-referenced comment over half a year old. I am also fine if I can get it a .apk running matplotlib by tinkering with python-for-android directly, though I don't know how that would work.
Lastly, I tried to download both numpy and matplotlib source code and add the modules locally to my package so buildozer would not need to download/care about them, but I don't know how that is done for large, complex modules like these (if it is even possible).
This is the sample code that I would like to get a .apk for (copied from How to get started/use matplotlib in kivy):
from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import matplotlib.pyplot as plt
plt.plot([1, 23, 2, 4])
plt.ylabel('some numbers')
class MyApp(App):
def build(self):
box = BoxLayout()
box.add_widget(FigureCanvasKivyAgg(plt.gcf()))
return box
MyApp().run()