Easy kivy app work on windows but not on Android - 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

Related

Buildozer how to package app with service

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!

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

Python Kivy - App that open url in a native web browser

I try to make a simple app that open a web page inside Kivy after clicking a button placed on a "Screen One".
I used this topic (Python - Showing a web browser/iframe right into the app) as reference but I didn't understand how to use the code provided by Michael...
So I tried this... and when I launch the apk (build with Buildozer) it didn't work :')
import kivy
kivy.require('1.9.2')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
# MICHAEL'S CODE
from kivy.utils import platform
from kivy.uix.widget import Widget
from kivy.clock import Clock
from jnius import autoclass
from android.runnable import run_on_ui_thread
WebView = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.renpy.android.PythonActivity').mActivity
class Wv(Widget):
def __init__(self, **kwargs):
super(Wv, self).__init__(**kwargs)
Clock.schedule_once(self.create_webview, 0)
#run_on_ui_thread
def create_webview(self, *args):
webview = WebView(activity)
webview.getSettings().setJavaScriptEnabled(True)
wvc = WebViewClient();
webview.setWebViewClient(wvc);
activity.setContentView(webview)
webview.loadUrl('http://www.google.com/')
# END OF MICHAEL'S CODE
Builder.load_string('''
<ScreenOne>:
BoxLayout:
Label:
text: "SCREEN 1"
Button:
text: "GO GO GO TO GOOGLE !"
on_press: root.open_browser()
<ScreenTwo>:
BoxLayout:
Label:
text: "SCREEN 2"
Button:
text: "GO GO GO TO SCREEN 1"
on_press:
root.manager.transition.direction = "right"
root.manager.transition.duration = 1
root.manager.current = "screen_one"
''')
class ScreenOne(Screen):
def open_browser(self):
return Wv()
class ScreenTwo(Screen):
pass
screen_manager = ScreenManager()
screen_manager.add_widget(ScreenOne(name="screen_one"))
screen_manager.add_widget(ScreenTwo(name="screen_two"))
class BrowserApp(App):
def build(self):
return screen_manager
app = BrowserApp()
app.run()
The app don't crash but just close when I start it.
What I'm doing wrong ? I'm sure that I don't use it the right way...
Log from adb logcat:
06-13 12:54:47.559 7429 7510 I python : ImportError: No module named android
06-13 12:54:47.579 7429 7510 I python : Python for android ended.
From the log you posted in the comments I extracted the two important lines:
06-13 12:54:47.559 7429 7510 I python : ImportError: No module named android
06-13 12:54:47.579 7429 7510 I python : Python for android ended.
This basically means that the copied code:
from android.runnable import run_on_ui_thread
won't work because it doesn't detect the android module. The module has a separate recipe, therefore you will need to add it to the requirements, so that it compiles the Cython code and adds it to your app, otherwise the import will always fail.
Basically you always want to search for 3-4 keywords when looking into such a messy logcat → "python", "Traceback", "Python for android", "kivy". There's a filter in buildozer for that if you use it:
android.logcat_filters = *:S python:D

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.

Qpython Kivy TextInput focus is not working

Focusing on the TextInput ends this simple Python script
using Qpython on an Android phone
from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
Builder.load_string("""
#:import kivy kivy
#:import sys sys
<Home>:
orientation: "vertical"
Label:
text: "testing textinput problem"
TextInput:
text: "123"
Label:
text: "kivy version %s" % kivy.__version__
""")
class Home (BoxLayout):
pass
runTouchApp (Home() )
There is no error message in the Runtime Log.
The error does not occur when the script is run on the PC.
The error occurs after Qpython switched to Kivy 1.8

Categories

Resources