【问题标题】:Kivy Android APK crashes when I flip the phone当我翻转手机时 Kivy Android APK 崩溃
【发布时间】:2016-04-09 01:23:12
【问题描述】:

我从 Kivy 和 Android 开始,尝试制作一个应用,同时使用 plyer 访问设备传感器。

我正在与:

  • 基维:1.9.1
  • Buildozer:0.32dev
  • SO(桌面):Ubuntu 14.04 LTS
  • 所以安卓:棉花糖 6.0

我从一个网络教程中获取了以下代码:

#-*-coding:utf8;-*-
#qpy:2
#qpy:kivy

from kivy.app 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
        try:
            accelerometer.enable() #enable the accelerometer
            Clock.schedule_interval(self.update, 1.0/24) #24 calls per second
        except:
            self.lblAcce.text = "Fallo al iniciar el acelerometro" #error

    def update(self, dt):
        txt = ""
        try:
            txt = "Aceleracion: \nX = %.2f\nY = %.2f\nZ = %2.f " %(
                accelerometer.acceleration[0], #read the X value
                accelerometer.acceleration[1], # Y
                accelerometer.acceleration[2]) # Z
        except:
            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__':
    TestApp().run()

并使用此 buildozer.spec 文件构建 APK(去掉注释块):

[app]

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

# (str) Package name
package.name = acc1

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

# (str) Source code where the main.py 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

[buildozer]

# (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

忘记设置了

android.permissions

但对此没有任何问题。问题是当我关闭(翻转)手机(从纵向到横向)时,应用程序崩溃了。我用谷歌搜索了它,但找不到答案。有什么想法吗?

谢谢!

【问题讨论】:

  • 尝试设置android.minapi = 13
  • 您应该运行buildozer android run logcat(或buildozer android_new run logcat,如果您使用的是新工具链)并发布应用崩溃时的相关输出部分。
  • @jligeza 成功了!谢谢!您可能希望自己获得 SO 点,这就是应该的,所以如果您愿意,请继续发布答案。 =)

标签: android python kivy buildozer


【解决方案1】:

可能是一个错误,设置android.minapi = 13 或更大。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-15
    • 2017-02-14
    相关资源
    最近更新 更多