Search code examples
pythonandroidlinuxkivybuildozer

Kivy app can't find/read my txt file in root directory Android


I created an app that just reads my txt and prints the contents to the screen with a Label, but it can't find my txt when I run the app on android, on windows works fine. Here is my code:

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout

class MainApp(App):
    def build(self):
        fl = FloatLayout()
        fl.add_widget(Label(text=open("settings.txt", "r").read(), halign="center"))
        return fl

MainApp().run()

What is wrong? And I will not use ConfigParser because it's already used in my project, this is just a sample code that I created for this question.

Any help will be appreciated


Solution

  • In your buildozer.spec file modify the line:

    source.include_exts = py,png,jpg,kv,atlas
    

    to:

    source.include_exts = txt,py,png,jpg,kv,atlas
    

    And verify that you have not excluded txt files elsewhere in the spec file.