You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Buildozer构建的Kivy安卓应用崩溃求助

Kivy安卓应用崩溃求助:精简代码仍无法定位问题

我试过所有能找到的方案和自己能想到的方法,都没法解决问题,也定位不到错误点。以下是我精简到最小规模的主代码文件和KV文件:

主代码文件

from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.graphics import Color, Line
from kivy.graphics import Rectangle
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout

class MenuScreen(Screen):
    def __init__(self,**kwargs):
        super(MenuScreen, self).__init__(**kwargs)

        try:
            picture_size = self.ids.main_grid.children[2].size[1]
            rect_size_x, rect_size_y = self.ids.main_grid.children[0].size[0],   self.ids.main_grid.children[0].size[1]
            multiplication = int(len(self.ids.main_grid.children)/4)
            scroll_height = multiplication*picture_size + multiplication*rect_size_y

            self.ids.main_grid.height = scroll_height

            size_ = (100,20)
            step = picture_size + rect_size_y
            pos_x, pos_y = 0, (rect_size_y - size_[1])/2 
            with self.ids.main_grid.canvas:
                
                for i in range(multiplication):
                    Color(rgb=(.6,.8,.2))
                    pos_x = (rect_size_x - size_[0])/2
                    self.rect = Rectangle(size=size_, pos=(pos_x, pos_y))
                    
                    pos_x = (rect_size_x - size_[0])/2 + rect_size_x
                    self.rect2 = Rectangle(size=size_, pos=(pos_x, pos_y))

                    Color(rgb=(.55,.6,.65))
                    self.line = Line(rectangle=self.rect.pos + self.rect.size, width = 2)
                    self.line = Line(rectangle=self.rect2.pos + self.rect2.size, width = 2)

                    pos_y += step
        except:
            pass

    pass

class Trenink(App):
    def build(self):
        
        sm = ScreenManager()
        menu_screen = MenuScreen()
        sm.add_widget(menu_screen)
        return sm
trenink = Trenink()
trenink.run()

KV文件

<MenuScreen>:
    name: "menu"
    BoxLayout:
        orientation: "vertical"
        size: 400, 800
        BoxLayout:
            orientation: "horizontal"
            spacing: 30
            padding: 20, 10, 20, 10
            size_hint: None, .08
            size: root.width, root.height/30
            canvas.before:
                Color:
                    rgba: .2,.2,.2, 1
                Rectangle:
                    pos: self.pos
                    size: self.size
            Button:
                text: "Celkove info"
                font_size: 16
            Button:
                text: "Cile"
                font_size: 16
            Button:
                text: "Seznam cviku"
                font_size: 16
        GridLayout:
            id: main_grid
            size_hint: 1, None
            height: 2500
            cols: 2
            rows: 12
            Button:
                text: "B1"
                background_color: 0, .6, 1, 1
                size_hint: None, None
                size: 200, 200
            Button:
                text: "B2"
                background_color: 0, .6, 1, 1
                size_hint: None, None
                size: 200, 200
            Label:
                size_hint: None, None
                size: 200, 50
                text: "Progres bar1"
            Label:
                size_hint: None, None
                size: 200, 50
                text: "Progres bar2"
            Button:
                text: "B3"
                background_color: 0, .6, 1, 1
                size_hint: None, None
                size: 200, 200
            Button:
                text: "B4"
                background_color: 0, .6, 1, 1
                size_hint: None, None
                size: 200, 200
            Label:
                size_hint: None, None
                size: 200, 50
                text: "Progres bar3"
            Label:
                size_hint: None, None
                size: 200, 50
                text: "Progres bar4"

Buildozer依赖配置

requirements = python3,kivy==2.0.0,pillow,kivy.uix.boxlayout,kivy.app,kivy.uix.scrollview,kivy.uix.screenmanager,kivy.graphics,kivy.uix.boxlayout,kivy.uix.gridlayout,kivy.uix.button,kivy.uix.label

应用安装到安卓设备后直接崩溃,我尝试用adb logcat查看日志,但不知道如何定位问题,恳请各位提供帮助。

内容的提问来源于stack exchange,提问作者Miloš Kadlec

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 17:20:37