Kivy安卓应用打开后瞬间崩溃。

问题描述 投票:0回答:1

我正试图开发一个简单的应用程序,使用谷歌翻译的API。该应用程序构建和安装正确,但当我打开我的手机上的应用程序,它只是崩溃,没有任何形式的错误信息。

这是我的 主.py 文件。

import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
from kivy.graphics import Color, Rectangle

from googletrans import Translator

Window.clearcolor = (0.2, 0.2, 0.2, 1)
Window.size = (450, 800)

tr = Translator()

# class in which we are defining action on click
class RootWidget(BoxLayout):

    def translate(self, text, src, dest):
        print(text, src, dest)
        if text != "":
            self.output_text.text = tr.translate(text, src=src, dest=dest).text
    def speak(self):
        print('speaking')
    def read(self):
        print('reading')

class TranslatorApp(App):

    def build(self):
        return RootWidget()

myApp = TranslatorApp()

myApp.run()

这是我的 翻译器.kv 文件。

<RootWidget>:

    input_text:input_text
    output_text:output_text
    src_lang:src_lang
    dest_lang:dest_lang

    BoxLayout:
        orientation: 'vertical'
        spacing: 5
        padding: 5

        BoxLayout:
            orientation: 'horizontal'
            spacing: 5
            size_hint: [1, 0.1]

            Label:
                text: 'Texto a traducir'
                halign: 'left'

            Label:
                text: 'Texto traducido'
                halign: 'left'

        BoxLayout:
            orientation: 'horizontal'
            spacing: 5
            size_hint: [1, 0.9]

            TextInput:
                id: input_text
                color: [180, 180, 180]
                size_hint: [0.5, 1]
            TextInput:
                id: output_text
                text: "s"
                color: [180, 180, 180]
                size_hint: [0.5, 1]

        BoxLayout:
            orientation: 'horizontal'
            spacing: 5
            size_hint: [1, 0.2]

            Button:
                text: 'Hablar'
                color: [0, 255, 255, .67]
                background_normal: ''
                background_color: [0, 0.5, 1, .85]
                on_press: root.speak()
                size_hint: [0.5, 1]

            Button:
                text:'Traducir'
                color: [0, 255, 255, .67]
                background_normal: ''
                background_color: [1, 1, 1, 0.7]
                on_press: root.translate(input_text.text, src_lang.text, dest_lang.text)
                size_hint: [0.5, 1]

            BoxLayout:
                orientation: 'vertical'
                spacing: 5

                BoxLayout:
                    orientation: 'horizontal'
                    spacing: 5

                    Label:
                        text: 'Idioma de\norigen'
                        halign: 'left'

                    Label:
                        text: 'Idioma de\ndestino'
                        halign: 'left'

                BoxLayout:
                    orientation: 'horizontal'
                    spacing: 5

                    TextInput:
                        id: src_lang
                        text: 'es'

                    TextInput:
                        id: dest_lang
                        text: 'en'

                Button:
                    text: 'Leer traducción'
                    on_press: root.read()

我运行这个命令 buildozer android debug 构建应用程序。android_new 为新的p4a工具链,但当我尝试时,我得到了这样的错误信息。

Unknown command/target android_new

我想添加buildozer.spec文件,但stackoverflow认为它是垃圾文件

android python-3.x kivy buildozer p4a
1个回答
0
投票

我觉得回答我自己的问题很愚蠢。

我已经添加了 googletrans 的规范文件,所以我认为这不是问题所在。在我试图解决这个问题的时候,我更新了模块,我看到有一些关于 googletrans 我所需要做的就是把这些依赖关系也添加到需求中去。

© www.soinside.com 2019 - 2024. All rights reserved.