Rodrigo E. Principe Rodrigo E. Principe - 4 months ago 35x
Android Question

Kivy Android APK crashes when I flip the phone

I am starting with Kivy and Android, trying to make an app, using also plyer to access the device sensors.

I am working with:

  • Kivy: 1.9.1

  • Buildozer: 0.32dev

  • SO (desktop): Ubuntu 14.04 LTS

  • SO Android: Marshmallow 6.0

I took the following code from a web tutorial:


from import App
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from plyer import accelerometer
from kivy.clock import Clock

class UI(FloatLayout):
def __init__(self, **kwargs):
super(UI, self).__init__(**kwargs)
self.lblAcce = Label(text="Accelerometer: ") #create a label at the center
self.add_widget(self.lblAcce) #add the label at the screen
accelerometer.enable() #enable the accelerometer
Clock.schedule_interval(self.update, 1.0/24) #24 calls per second
self.lblAcce.text = "Fallo al iniciar el acelerometro" #error

def update(self, dt):
txt = ""
txt = "Aceleracion: \nX = %.2f\nY = %.2f\nZ = %2.f " %(
accelerometer.acceleration[0], #read the X value
accelerometer.acceleration[1], # Y
accelerometer.acceleration[2]) # Z
txt = "No se puede leer el acelerometro!" #error
self.lblAcce.text = txt #add the correct text

class TestApp(App):
def build(self):
# display a button with the text : Hello QPython
usi = UI()
return usi

if __name__== '__main__':

and build the APK with this buildozer.spec file (took off the commented blocks):


# (str) Title of your application
title = Acelerometro 1

# (str) Package name = acc1

# (str) Package domain (needed for android/ios packaging)
package.domain = org.test

# (str) Source code where the live
source.dir = .

# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas

# (str) Application versioning (method 1)
version = 1.0

# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
requirements = kivy, plyer

# (str) Supported orientation (one of landscape, portrait or all)
orientation = all

# (bool) Indicate if the application should be fullscreen or not
fullscreen = 1


# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 2

# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
warn_on_root = 1

I forgot to set the


but had no problem about that. The problem is that when I turn down (flip) the phone (from portrait to landscape) the app crashes. I googled it, but couldn't find the answer. Any ideas?

Thank you!


Probably a bug, set android.minapi = 13 or greater.