Kivy App crash in Android but not in PC. Buildozer 'KeyError: 'kivy.garden.matplotlib''

Viewed 1062

Versions:

  • Python: 3.8.5
  • OS: Manjaro 20.04
  • Buildozer: 1.2.0
  • Kivy: 1.11.1

Description:

I want to plot graphic of matplotlib with command "from kivy.garden.matplotlib.backend_kivyagg import FigureCanvasKivyAgg" in .py file. This command works in PC but not in Android.

Spec file:

    requirements: python3,kivy==2.0.0rc3,https://github.com/kivymd/KivyMD/archive/master.zip,sdl2_ttf==2.0.15, matplotlib

logcat | grep python

    09-14 11:32:56.530 17786 18857 I python  :  KeyError: 'kivy.garden.matplotlib'
    09-14 11:32:56.531 17786 18857 I python  : Python for android ended.
1 Answers

As already stated by the error, you dont have the garden requirements. It works on your pc because you probably did:

garden install matplotlib

At some point in your pc hence you have the garden flower.But that is only half the problem. Thing is, kivy garden is now deprecated so you should stop using it, for now to use a garden flower in your app, you should do:

garden install --app some_flower

This is because garden flowers have been deprecated in favour of pip packages but not all of them have been moved to pypi so if your desired package hasnt been moved yet, use the command above otherwise, just install it normally with pip and ialso add it in your requirements. The other major problem you have is that MATPLOTLIB WONT WORK IN ANDROID This has been a major issue and discussed for a while now but AFAIK no one is currently working on a fix,If you only need to plot a simple graph though,there is a garden package called graph, install it with:

python -m pip install https://github.com/kivy-garden/graph/archive/master.zip

Then use it in your app, this one is just python so it will work on android, tried and tezted by me. If you are wondering how to use it, there is an example on its README

You can then include that url in your requirements in buildozer(like you did with KivyMD

Quick Edit: Matplotlib now works great with kivy

Related