Buildozer how to package app with service - android

I have a simple program to try making an app with a service that plays a song. Here is my code:
main.py
from kivy.app import App
from kivy.lang import Builder
from kivy.utils import platform
kv = '''
Button:
text: 'push me!'
'''
class ServiceApp(App):
def build(self):
if platform == 'android':
from android import AndroidService
service = AndroidService('Song App', 'Song Playing')
service.start('service started')
return Builder.load_string(kv)
ServiceApp().run()
and service main.py
from kivy.core.audio import SoundLoader
#I have a file called song.wav in the same directory
sound = SoundLoader.load('song.wav')
if sound:
sound.play()
This works perfectly in Kivy Launcher, but I don't know how I can package this with buildozer. Any help would be appreciated!

Related

Python Kivy Android

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

Easy kivy app work on windows but not on Android

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

how to connect external libraries in Kivy

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

android file not working with numpy recipe

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.

"ImportError: Cannot import name spawnu" while building apk using kivy

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!!

Categories

Resources