Recently I have created a dummy android app using Python2 and Kivy. Binded it using buildozer but when I installed it on my android device everything going good so far but app is not loading the screen. It opens and instantly closed it, and no error(s) displayed :(
I am using kivy 1.11.0 and buildozer version is 0.34. Application is working before binding it to .apk
Python Code
import kivy
kivy.require('1.11.0')
#from kivy.core.window._window_sdl2 import _WindowSDL2Storage
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
class screen1(GridLayout):
def __init__(self, **kwargs):
super(screen1, self).__init__(**kwargs)
self.cols = 2
self.add_widget(Label(text="hello world!"))
self.add_widget(Label(text="bye world!"))
class SampleKivy(App):
def build(self):
return screen1()
if __name__ == "__main__":
SampleKivy().run()
Related
I'm trying to study Kivy, so I've done a simple gui that work on windows but when I run it on Android with Kivy Launcher I'm getting this error trought ADB LOGCAT :
This is a simple kv code :
#:kivy 1.0.9
<ROT>:
FloatLayout:
AnchorLayout:
anchor_x:"center"
anchor_y: "top"
Button:
size_hint : 1,1
text : "prova"
on_press: root.press()
and this is the main.py :
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
class ROT(Widget):
def press(self):
print "ciao"
pass
class PongApp(App):
def build(self):
self.root = Builder.load_file('questionario.kv')
return ROT()
if __name__ == '__main__':
PongApp().run()
I can't understand why it doesn't want to work
When you try to build the application. Application normally collected and only runs if there is no outside application libraries. When you attempt to connect networkx library. Appendix normally gather. But when you try to run directly on the device. Pops saver "Loadind ..." and the application falls. What you need to change to get everything working.
Attached is the application code:
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.scatter import Scatter
from kivy.uix.boxlayout import BoxLayout
from kivy.graphics.vertex_instructions import *
from kivy.graphics.context_instructions import Color
import networkx as nx
G = nx.Graph()
G.add_node(1)
G.add_node(2)
G.add_node(3)
G.add_node(4)
G.add_edge(1,2)
G.add_edge(1,3)
G.add_edge(3,4)
G.add_edge(2,3)
class SimpleKivy(App):
def build(self):
b = BoxLayout()
l = Label(text=str(nx.shortest_path(G,1,4)))
textinput1 = TextInput(text=str(nx.shortest_path(G,1,4)))
textinput1.bind(text=l.setter('text'))
f = FloatLayout()
s = Scatter()
s.add_widget(l)
f.add_widget(s)
b.add_widget(f)
b.add_widget(textinput1)
return b
if __name__ == "__main__":
SimpleKivy().run()
In your buildozer.spec file, line 39 add your third-party requirments.
requirements = kivy,networkx, # or what ever
I am using example from Kivy documentation, only line i added is import numpy. After packaging it for android i cant run on my phone it never starts. However on removing this line and then building works fine.
python file: main.py
__version__="1.0.0"
import colorsys
import numpy as np
import kivy
kivy.require('1.0.7')
from kivy.animation import Animation
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def animate(self, instance):
animation = Animation(pos=(100, 100), t='out_bounce')
animation += Animation(pos=(200, 100), t='out_bounce')
animation &= Animation(size=(500, 500))
animation += Animation(size=(100, 50))
animation.start(instance)
def build(self):
button = Button(size_hint=(None, None), text='plop',
on_press=self.animate)
return button
if __name__ == '__main__':
TestApp().run()
In buildozer.spec file under requirement i have included kivy, numpy.
Check the log to see what's wrong.
I wrote a simple Kivy app on Mac OsX that replicates buttons:
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
class ButtonApp(App):
def add_button(self, none):
button = Button(text='Press Me too!')
button.bind(on_press=self.add_button)
self.b.add_widget(button)
def build(self):
self.b = BoxLayout()
button = Button(text="Press me!")
button.bind(on_press=self.add_button)
self.b.add_widget(button)
return self.b
if __name__ == "__main__":
ButtonApp().run()
However, when I initiate the buildozer file with buildozer init, and run it with buildozer android debug I get the following error
self.target.build_package()
File "/usr/local/lib/python2.7/site-packages/buildozer/targets/android.py", line 517, in build_package
version = self.buildozer.get_version()
File "/usr/local/lib/python2.7/site-packages/buildozer/__init__.py", line 675, in get_version
' (looking for `{1}`)'.format(fn, regex))
Exception: Unable to find capture version in ./main.py
(looking for `__version__ = ['"](.*)['"]`)
I've tried many solutions including switching the locations of the file, changing the version, adding __version__ = "1.2.0" to main.py file, and all with no success. What am I doing wrong?
Buildozer works only on linux for the android package, this error is because you were on OSX
I was building a simple android app using kivy using the below code:
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.scatter import Scatter
from kivy.uix.floatlayout import FloatLayout
class TutorialApp(App):
def build(self):
f = FloatLayout()
s = Scatter()
l = Label(text="Hello!",
font_size=150)
f.add_widget(s)
s.add_widget(l)
return f
if __name__ == "__main__":
TutorialApp().run()
I am building this code into an apk using buildozer.
I wrote
buildozer android debug
This gave the following error:
http://imgur.com/z9TJMhC
How can I rectify this error.
It seems that python or the kivy compiler is unable to import a package named spawnu.Spawnu is part of pexpect package. Try
sudo pip install pexpect
sudo pip install pexpect --upgrade
Worked for me. Good Luck!!