繁体   English   中英

"Kivy 应用无法在安卓手机上启动"

[英]Kivy app won't launch on android phone

我正在制作一个简单的应用程序,以便(将来)从网页中查看一些内容。 目前它在 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()

您应该按照kivy文档中的调试说明进行操作如果不能明确给出答案,请将logcat输出粘贴到此处。

我过去有同样的问题,我通过在 .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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM