我用kivy写了一个简单的应用程序。它在我的桌面上运行得很好,但我希望它能在Android上运行。但是,当我将它安装到我的Android手机上时,它会在启动时崩溃。
应用程序在局域网上播放,等待回复。然后,任何回复的人都会被添加到列表中并显示在屏幕上。
这是我的代码:
import kivy
import random
import socket
import threading
kivy.require('1.7.2') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from functools import partial
from multiprocessing import Process, Queue
from time import sleep
import socket
import random
CHECK_MESSAGE = "Who is alive?"
class Communicator:
def requester(self):
address = ('<broadcast>', 54545)
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
string_list =[]
while True:
#print "broadcasting done by " + self.my_name
client_socket.sendto(CHECK_MESSAGE, address)
recv_data, addr = client_socket.recvfrom(2048)
if self.my_name == recv_data or recv_data in string_list:
sleep(3)
continue
string_list.append(recv_data)
self.callback(string_list)
sleep(3)
def replyer(self):
address = ('', 54545)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
server_socket.bind(address)
#print my_name
while True:
#print "Listening"
recv_data, addr = server_socket.recvfrom(2048)
if recv_data == CHECK_MESSAGE:
server_socket.sendto(self.my_name, addr)
def __init__(self, callback_function):
self.callback = callback_function
self.my_name = socket.gethostname() + ' ' + str(int(random.random()*10000))
def start_all(self):
self.start_server()
self.start_client()
def start_client(self):
client = threading.Thread(target=self.requester)
client.daemon = True
client.start()
def start_server(self):
server = threading.Thread(target=self.replyer)
server.daemon = True
server.start()
class Client:
name = ''
def get_name(self):
return self.name
client_list =[]
class Pong(Screen):
grid_l = ObjectProperty(None)
top_lbl = ObjectProperty(None)
list_of_peers = ObjectProperty(None)
def search_btn_pressed(self, string_list):
#if self.queue.qsize() > 0:
#print "sieze:" , self.queue.qsize()
grid = self.grid_l
grid.bind(minimum_height=grid.setter('height'),
minimum_width=grid.setter('width'))
x = random.randint(2, 5)
#if self.list_of_peers is not None:
# grid.remove_widget(self.list_of_peers)
self.grid_l.clear_widgets()
self.list_of_peers = GridLayout(cols=1, row_default_height=40,
row_force_default=False)
self.list_of_peers.bind(minimum_height=grid.setter('height'),
minimum_width=grid.setter('width'))
print(socket.gethostbyname(socket.getfqdn()))
for i in string_list:
btn1 = Button(size_hint=(1, None))
btn1.text = str(i)
#btn1.bind(on_release=partial(self.btn1_pressed, result))
self.list_of_peers.add_widget(btn1)
grid.add_widget(self.list_of_peers)
def btn1_pressed(self, result, *args):
new_text = result
self.top_lbl.text = new_text
def btn2_pressed(self, *args):
self.grid_l.clear_widgets()
#pass
class PongApp(App):
def build(self):
my_app = Pong()
queue = Queue()
my_app.queue = queue
Communicator(my_app.search_btn_pressed).start_all()
return my_app
if __name__ == '__main__':
App = PongApp().run()
和pong.kv:
#:kivy 1.7.2
<Pong>:
scroll_view: scrollviewID
top_lbl: lblID
grid_l: gridlayoutID
AnchorLayout:
size_hint: 1, .1
pos_hint: {'x': 0, 'y': .9}
anchor_x: 'center'
anchor_y: 'center'
Label:
id: lblID
text: 'This is the app..'
Button:
size_hint: 1, .1
pos_hint: {'x': 0, 'y': .8}
text: 'Refresh?'
#on_release: root.search_btn_pressed()
ScrollView:
id: scrollviewID
orientation: 'vertical'
pos_hint: {'x': 0, 'y': 0}
size_hint: 1, .8
bar_width: '8dp'
GridLayout:
id: gridlayoutID
cols: 1
size_hint: 1, None
row_default_height: 40
row_force_default: False
我跑了“./distribute.sh -m”openssl pil kivy“” 然后 “./build.py --dir~ / Desktop / MyProject / --package org.test.florin --name “ShareAll”--version 0.0.1 - 允许INTERNET调试安装“
这会将应用程序发送到我的手机,但是当我启动它时,它会崩溃。 我错过了什么吗?不知道如何得到任何错误..
这是我第一次使用kivy(或Android)
这是adb logcat http://pastebin.com/embed_js.php?i=28KaFM79
不知道为什么会那么大..
答案 0 :(得分:0)
I / python(16193):找不到main.pyo / main.py。
这是您文件中的错误(您可以通过点击python
或使用adb自己的语法来查看与kivy相关的行。)
所以...是你的主文件main.py?如果是这样的话,它不会因某种原因被包括在内。