Search code examples
pythonpython-3.xlinuxapkbuildozer

Successfully created apk file crashing when downloaded on phone


I managed to successfully create an apk file using buildozer from my pygame python file. however when i download the apk on my phone (google pixel 3a if relevant) it instantly crashes on opening it. I have tried a test file which has a simple script of changing the background colour on click, and it managed to work just fine so it should be an issue with the code of my actual game. What are the possible reasons this could happen, I've have made sure each of the images have the correct path using os.path.abspath(".")+"/". Anyone one have any ideas as how to fix this problem?


Solution

  • It seems likely that your image paths are what's causing the problem, if not, some other unhandled exception is causing the crash.

    You could implement an image loading helper that will create a placeholder image if it can't find the supplied path. Something like this (untested):

    def load_image(path_to_image):
        try:
           img = pygame.image.load(path_to_image).convert_alpha()
        except:
            # TODO: Log the exception
            # grab the first installed font
            sys_font = pygame.font.SysFont(pygame.font.get_fonts()[0], 20)
            img = sys_font.render("‽", True, "red")
        return img