【问题标题】:Kivy app won't launch on android phoneKivy 应用无法在安卓手机上启动
【发布时间】:2022-01-27 16:57:14
【问题描述】:

我正在制作一个简单的应用程序,以便(将来)查看网页中的一些内容。目前它在 Windows 上完美运行(它登录并提供一个新页面)。但它停止在我的手机上运行。它不会使用 kivy 启动器启动。它不能太大。我不知道是什么问题。我已经尝试了一切... 这是我的代码:

        #!/usr/bin/python
    # -*- coding: iso-8859-15 -*-
    import kivy
    kivy.require('1.8.0')
    import webbrowser
    import urllib.request
    import re

    from kivy.app import App
    from kivy.uix.floatlayout import FloatLayout
    from kivy.uix.anchorlayout import AnchorLayout
    from kivy.uix.gridlayout import GridLayout
    from kivy.uix.button import Button
    from kivy.uix.label import Label
    from kivy.uix.screenmanager import ScreenManager, Screen
    from kivy.properties import ObjectProperty, StringProperty 
    from kivy.network.urlrequest import UrlRequest
    from kivy.uix.popup import Popup

    from kivy.lang import Builder

    Builder.load_string("""
    <Phone>:
        sm: _screen_manager
        usernameField: username
        passwordField: password
        AnchorLayout:
            anchor_x: 'center'
            anchor_y: 'top'
            ScreenManager:
                size_hint: 1, .9
                id: _screen_manager
                Screen:
                    name: 'Avakuva'             

                    Label: 
                        markup: True
                        text: '[size=50]Welcome to [color=8b00c3]Pelltech app![/color][/size]'
                    FloatLayout:
                        Button:
                            text: 'Info'
                            size_hint: .2, .1
                            pos_hint: {'x': .3, 'y': .1}
                            on_press: _screen_manager.current = 'Info'  
                        Button:
                            text: 'Login' 
                            size_hint: .2, .1
                            pos_hint: {'x': .5, 'y': .1} 
                            on_press: _screen_manager.current = 'Login'
                Screen:
                    name: 'Login'
                    GridLayout:
                        rows: 3
                        cols: 2
                        padding: 200
                        spacing: 10
                        Label:
                            text: 'User name:'
                        TextInput:
                            id: username
                        Label:
                            text: 'Password:'
                        TextInput:
                            id: password
                            password: True
                        Label:
                            text:''
                        Button:
                            text:"Log in"
                            on_press: root.goToBurners(username.text, password.text)

                Screen:
                    name: 'Info'
                    GridLayout:
                        rows:2
                        cols:1
                        padding: 200
                        spacing: 10
                        Label:
                            haling: 'justify'
                            text:'This app is for pelletburner owners. For more information contact:'
                        Button:
                            text:'Pelltech'
                            on_press: root.openPage()
                    FloatLayout:
                        Button:
                            text: 'Back'
                            size_hint: .2, .1
                            pos_hint: {'x': .4, 'y': .1}
                            on_press: _screen_manager.current = 'Avakuva'
                Screen:
                    name: 'Menu'
                    GridLayout:
                        rows:3
                        cols:1
                        padding:200
                        spacing: 10
                        Label:
                            markup: True
                            text: 'Menüü:'
                        Button:
                            text: 'Minu põletid'  
                            on_press: _screen_manager.current = 'põletid'
                        Button: 
                            text: 'Muu'

                Screen:
                    name: 'põletid'
                    GridLayout:
                        rows:4
                        cols:1
                        padding: 200
                        spacing: 10
                        Label:
                            markup: True
                            text: 'Burner 1'

                        Label:
                            markup: True
                            text: 'Burner 2'
                        Label:
                            markup: True
                            text: 'Burner 3'
                        Button:
                            text: 'Back'
                            size: 50, 50
                            on_press: _screen_manager.current = 'Menu' 
    """)

    class Phone(FloatLayout):
        def openPage(self):
            webbrowser.open('http://www.pelltech.eu')

        def goToBurners(self, username, password):
            #import pdb; pdb.set_trace()
            print("1")
            params = urllib.parse.urlencode({'username':username, 'password':password, 'nextPage':'/'})
            headers={'Content-type':'application/x-www-form-urlencoded','Accept':'text/plain'}
            print("2")
            req = UrlRequest('http://10.1.1.116/account/login?',req_headers=headers, req_body=params, method = "POST", on_redirect = self.gotResults, on_success=self.loginSuccess, on_failure=self.connectionFail)
            timeout = 10

        def newSuccess(self, req, result):
            print("new success")
            print(req.resp_status)
            print(result.decode())
            sm=ObjectProperty(ScreenManager())
            self.sm.current = 'Menu'

        def newFail(self, req, result):
            print("new fail")
            print(req.resp_status)
            print(result.decode())

        def newRedirect(self, req, result):
            print("new redirect")
            print(req.resp_status)
        print(result.decode())

    def gotResults(self, req, result):
        print(req.resp_status)
        print('on_redirect tõi siia') 
        #print(req.resp_headers)
        headerText = str(req.resp_headers)
        cookieStart = headerText.find('sessionid')
        #cookieEnd = headerText.find('expires')-2
        cookieEnd = headerText.find('=/')+2
        cookie = headerText[cookieStart:cookieEnd]
        print(cookie)
        headers={'Cookie': cookie}
        req = UrlRequest('http://10.1.1.116/',req_headers=headers, method = "POST", on_redirect = self.newRedirect, on_success=self.newSuccess, on_failure=self.newFail)

    def loginSuccess(self, req, result):
        print(req.resp_status)
        print("on_success t6i siia")
        print (result.decode())
        content = Button(text = 'Proovi uuesti!', size = (20,20))
        popup = Popup(title= 'Login ebaõnnestus!', content = content, size_hint = (None, None), size = (400,400), auto_dismiss = False)
        content.bind(on_press = popup.dismiss)
        popup.open()
        self.usernameField.text = ""
        self.passwordField.text = ""

    def connectionFail(self, req, result):
        print("on_failure t6i siia")
        print(req.resp_status)
        content = Button(text = 'Proovi uuesti!', size = (20,20))
        popup = Popup(title= 'Ühendus serveriga puudub!', content = content, size_hint = (None, None), size = (400,400), auto_dismiss = False)
        content.bind(on_press = popup.dismiss)
        popup.open()

class TestApp(App):
    def build(self):
        return Phone()

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

【问题讨论】:

    标签: android python kivy


    【解决方案1】:

    您应该按照调试说明in the kivy documentation,如果它没有使答案清晰,请在此处粘贴 logcat 输出。

    【讨论】:

    • 同时发布您的 buildozer.spec。您可能没有包含您的应用所需的必要 Android 权限(互联网)
    • 嗯..我应该提到我正在用崇高的文本编写它并使用 kivy 启动器应用程序来启动我的应用程序(我提到过)。我会尝试安装一个android模拟器并获取日志...
    【解决方案2】:

    我过去有同样的问题,我通过在 .spec 中添加要求来解决

    这个要求对我有用:

    requirements = hostpython3==3.7.8,python3==3.7.8,kivy==1.11.1, certifi,chardet, lxml, docutils, future, idna, Kivy-Garden, Pygments, requests, six, soupsieve, urllib3, deep-translator, arabic-reshaper, python-bidi, openssl, pyopenssl, numpy, pytz, python-dateutil, pandas, setuptools, zope.interface, datetime
    

    您必须在您的应用正在使用的需求中编写所有模块和父模块。

    要知道你的应用正在使用的模块有两种方法:

    1. 在 powershell 的当前应用文件夹中运行命令 pip freeze
    2. 如下图所示安装所有模块,以帮助安装您的应用程序模块

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-24
      • 1970-01-01
      • 2021-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多