在win10下如何使用kivy和buildozer生成android应---填坑篇

本文介绍了在Windows10环境下,如何利用Kivy和Buildozer在Linux子系统(如Docker、WSL、VMware或VirtualBox)上创建Android应用,包括搭建Linux环境、更换国内源、解决网络问题以及处理Gradle下载难题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在win10下使用kivy和buildozer生成android应用,在kivy的官方文档里面就写的很清楚

Create a package for Android — Kivy 2.2.1 documentation

真的就是这么简单,前提是,要有一个能有效上网的linux!能有效上网linux!能有效上网linux!

重要的事情说三遍。

Buildozer不能在windows下运行,所以搭建一个能有效上网的linux非常重要。

可以使用docker,可以使用WSL,可以使用VMWARE或者virtualbox,等等。。。

作者淘的主机使用的是win10专业版,这几个方法都亲自体验了一遍,体验如下:

1. 使用VMWARE和virtualbox

好处是可以安装和使用vscode等IDE,使用体验最为更完整。可以插入手机直接在手机上调试。

缺点是安装费时费力占用主机资源较多。VMWARE比virtualbox稳定一些。特别是virtualbox的增强功能,不知道为啥,一安装就死机,必须删掉重装。

可以参考这个文章

import os import time import speech_recognition as sr import pyttsx3 from kivy.app import App from kivy.uix.boxlayout import BoxLayout from kivy.uix.button import Button from kivy.uix.label import Label from kivy.core.window import Window from kivy.clock import Clock from threading import Thread from plyer import notification # 新增通知模块 class VoiceAssistantApp(App): def build(self): self.title = "语音控制助手" self.layout = BoxLayout(orientation='vertical', spacing=10, padding=20) # 语音反馈 self.engine = pyttsx3.init() self.engine.setProperty('rate', 150) # 优化语速 # 录音控制 self.recording = False self.recognizer = sr.Recognizer() # 移动端适配 Window.size = (360, 640) # 设置默认分辨率 self.layout.bind(minimum_height=self.layout.setter('height')) # 界面组件 self.status_label = Label(text="等待指令...", size_hint_y=None, height=50) self.command_label = Label(text="识别结果:", size_hint_y=None, height=50) self.start_button = Button(text="开始录音", size_hint=(1, None), height=60) self.stop_button = Button(text="停止录音", size_hint=(1, None), height=60) # 添加交互 self.command_label.bind(size=self.command_label.setter('text_size')) self.layout.add_widget(self.status_label) self.layout.add_widget(self.command_label) self.layout.add_widget(self.start_button) self.layout.add_widget(self.stop_button) return self.layout def speak(self, text): """语音反馈""" self.engine.say(text) self.engine.runAndWait() # 新增通知功能 notification.notify(title="语音助手", message=text, timeout=3) def start_recording(self, instance): """开始录音线程""" if not self.recording: self.recording = True self.status_label.text = "正在录音..." Thread(target=self.listen_for_command).start() def stop_recording(self, instance): """停止录音""" self.recording = False self.status_label.text = "等待指令..." def listen_for_command(self): """监听语音指令""" with sr.Microphone() as source: self.recognizer.adjust_for_ambient_noise(source) audio = self.recognizer.listen(source) try: # 使用Google语音识别API command = self.recognizer.recognize_google(audio, language='zh-CN') self.command_label.text = f"识别结果:{command}" self.execute_command(command) except sr.UnknownValueError: self.command_label.text = "识别失败,请重试" self.speak("抱歉,我没听懂,请重试") except sr.RequestError: self.command_label.text = "网络错误" self.speak("网络连接失败") def execute_command(self, command): """执行指令""" command = command.lower() # 示例指令(可扩展) if "打开浏览器" in command: self.speak("正在打开浏览器") os.system("am start -a android.intent.action.VIEW -d https://www.baidu.com") elif "播放音乐" in command: self.speak("正在播放音乐") os.system("mpg321 ~/Music/song.mp3 &") # 使用跨平台播放器 elif "关闭手机" in command: self.speak("正在关闭手机") os.system("adb shell input keyevent 26") # 通过ADB模拟按键 else: self.speak("抱歉,我暂时无法执行这个操作") self.command_label.text += "(无匹配指令)" if __name__ == '__main__': VoiceAssistantApp().run() 打包一下这个软件
最新发布
03-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值