Search code examples
androidpythonkivypython-3.5pyjnius

Kivy pyjnius with Buildozer - Adding jnius to the app causes it to crash after starting it


after adding these lines of code to my kivy app, when i start it on my android 4.4.4 the app immediately crashes

from jnius import autoclass
try:
    Environment = autoclass('android.os.Environment')
    sdpath = Environment.get_running_app().getExternalStorageDirectory()

# Not on Android
except:
    sdpath = App.get_running_app().user_data_dir

I checked ADB to see if any errors come up but nothing came up except

03-01 17:44:19.813: E/InputDispatcher(898): channel '437f0100 org.renpy.android.PythonActivity (s)' ~ Channel is unrecoverably broken and will be disposed!

EDIT

It seems the line sdpath = Environment.get_running_app().getExternalStorageDirectory() is the one causing the crash


Solution

  • Actually I checked adb logcat and observed that Environment.get_running_app().getExternalStorageDirectory() raises

    AttributeError: type object 'android.os.Environment' has no attribute 'get_running_app'

    Use sdpath = Environment.getExternalStorageDirectory().getAbsolutePath() instead.