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

使用Buildozer打包的Kivy应用在手机黑屏,电脑及Kivy Launcher可正常运行

Fixing Kivy App Black Screen After Buildozer APK Packaging

Hey there! I’ve dealt with this exact black screen issue a few times when building Kivy apps for Android, so let’s walk through the most likely fixes to get your button app working properly:

1. Validate Your Buildozer Spec Configuration

First, double-check your buildozer.spec file—small mismatches here are a common culprit:

  • Match Kivy versions: Make sure the requirements line uses the exact same Kivy version you used for desktop development. For example, if you built with Kivy 2.2.1 locally, set:
    requirements = python3,kivy==2.2.1
    
    Version inconsistencies can break rendering or component initialization on Android.
  • Adjust Android API level: Set android.api to a level compatible with your phone. If your device runs Android 12/13, use android.api = 33; for older devices, try 29 or 30. Avoid using the absolute latest API unless you’ve tested compatibility.
  • Add basic permissions: Even if your app doesn’t need internet, adding INTERNET permission can resolve hidden loading issues. Update this line:
    android.permissions = INTERNET
    

2. Dig Into Logcat for Error Details

The best way to pinpoint the issue is to check your app’s runtime logs on Android:

  • Run this command in your project directory while your phone is connected via USB (with debugging enabled):
    buildozer android logcat
    
  • Launch the app on your phone, then look for error messages in the log output. Common issues include:
    • Typos or syntax errors in your .kv file that didn’t break desktop/Kivy Launcher but crash on Android.
    • Unhandled exceptions in your button’s callback methods (even a missing pass or incorrect variable reference can cause a silent crash).
    • Missing resources (like images or fonts) that you assumed were bundled correctly.

3. Simplify Your Code to Isolate the Problem

Strip your app down to the smallest working version with a button, then rebuild:

from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
    def build(self):
        btn = Button(text="Click Me")
        btn.bind(on_press=self.on_click)
        return btn

    def on_click(self, instance):
        print("Button clicked!")

if __name__ == "__main__":
    TestApp().run()

If this simplified app works, gradually reintroduce parts of your original code until the black screen returns. This will help you identify exactly which component or line is causing the issue.

4. Fix Rendering or Initialization Quirks

Sometimes Android-specific rendering settings are to blame:

  • Add these lines at the very top of your main.py file to disable multisampling, which can resolve black screen issues on some devices:
    from kivy.config import Config
    Config.set('graphics', 'multisamples', '0')
    
  • Double-check that your build() method actually returns a root widget. It’s easy to accidentally omit the return statement, which leaves the app with no UI to display.

Hopefully one of these steps gets your app running smoothly on Android!

内容的提问来源于stack exchange,提问作者S. X. Apo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:16:27