Search code examples
androidkivybuildozerfile-access

Kivy App for Android Unable to Load Image


My Kivy app deployed to Android via Buildozer no longer launches properly on Android since I have added .jpg and .wav files (used as background images and app sounds). It runs just fine on my Window machine.

adb catlog gives me the following warning: Unable to load image </data/user/0/org.test.galaxy/files/app/assets/images/bg1.jpg>. But the kicker is that if I navigate to this filepath within my android emulator, that file indeed exists.

View all my code in this public repo

This error is thrown when executing line 10 of my galaxy.kv which attempts to set the background info of my Rectangle with source: root.resource_path('assets/images/bg1.jpg')

Originally, I was just using relative pathing and leaving it all up to Buildozer to handle the OS specific pathing (I've read someplace that this is supposed to work), but since I have this error, I've included the resource_path() (credit to someone on stackoverflow) method which is supposed to take the OS specific pathing into account. Here is what that code looks like:

def resource_path(self, relative_path):
    base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
    print('base path:', base_path)
    return os.path.join(base_path, relative_path)

Some relevant lines from my buildozer.spec (again, view my whole repo with the link above):

source.include_exts = py,png,jpg,kv,atlas,wav,ttf
...
requirements = python3,kivy

I'm new to Kivy and Buildozer and I've obviously missed something about how to access static files. Any help will be much appreciated.


Solution

  • it may be due to the too high resolution of your bg image. Try again with a smaller image.