Florin Acsinte Florin Acsinte - 3 months ago 31
Python Question

Kivy app crashing on Android

I wrote a simple app using kivy. It works just fine on my desktop, but i want it to run on Android. However, when i install it to my Android phone, it crashes on startup.

The app broadcasts on the lan, waiting for a reply. Then whoever replies is added to a list and displayed on the screen.

this is my code:

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()


and 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


i ran " ./distribute.sh -m "openssl pil kivy" "
and then
"./build.py --dir ~/Desktop/MyProject/ --package org.test.florin --name
"ShareAll" --version 0.0.1 --permission INTERNET debug installd "

This gets the app to my phone, but when i start it up, it crashes.
Am i missing something? Dont know how to get to any errors..

It's my first time with kivy (or Android for that matter)

This is the adb logcat
http://pastebin.com/embed_js.php?i=28KaFM79

dont know why it's that big..

Answer

I/python (16193): No main.pyo / main.py found.

This is the error in your file (you can see the kivy-related lines by grepping python or using adb's own syntax for this).

So...is your main file called main.py? If so, it's not getting included for some reason.

Comments