i am new to kivy and would like some help guys .
i am building a Kivy App with buildozer for android , that uses an outsource API from cryptocompare.com
it is a very simple app that shows the Cryptocurrency prices , live updated.
the app crashes instantly when opened ..
i removed the API and created a Dict instead, just to test if the App will work or not , and the app runs perfectly on android .. when i put back the API , it just keep crashing .
note that the app works fine on Pycharm with no error .. also the Buildozer gives no error ..
i've been trying to find out the problem for so long .
tried every possible way . no luck.
almost included everything in android.permissions with no luck also .
this is my app code
from kivymd.app import MDApp
from kivymd.uix.screen import Screen
from kivymd.uix.list import MDList, TwoLineListItem
from kivy.uix.scrollview import ScrollView
from kivy.network.urlrequest import UrlRequest
class CryptoPrices(MDApp):
def build(self):
screen = Screen()
scroll = ScrollView()
listview = MDList()
scroll.add_widget(listview)
def got_json(req, result):
for x, y in result.items():
name = x
symbol = str(y["USD"]) + " USD"
item1 = TwoLineListItem(text=name, secondary_text=str(symbol))
listview.add_widget(item1)
req = UrlRequest('https://min-api.cryptocompare.com/data/pricemulti?fsyms=BTC,BCH,LTC,XLM,DASH,XEM,LIBRA,BNB,ETH,XMR,XRP,LTC&tsyms=USD', got_json)
screen.add_widget(scroll)
return screen
if __name__ == '__main__':
CryptoPrices().run()
link to buildozer.specs
https://textuploader.com/1f7ie
link to log file
https://textuploader.com/1f7ii
Two possible issues:
You may need to request runtime permissions. See runtime permissions
You might need to add requests to your requirements in the spec file.
From the buildozer.spec file, you have to set internet permissions.
By default this option is commented, just uncomment it and the app should work fine.
The logfile that you have added is buildozer log when the app is being built. To get the app log when it's running, add the logcat function (buildozer android logcat) In app logs you can find what causing your app to crash any requirements or permission or anything else
Related
I build an android app with Python and Kivy. The app works fine but I can't print some localisation details in my own langage (french).
Here is a simple example I wanted to work, and I can't achieve this :
It compiles with
buildozer -v android debug
I can install it on my phone, but when it runs it failed, my program can't set up the locale (I got the error msg with logcat)
What is the correct way to localise properly an Android app with kivy ?
import os
import locale
from datetime import date
from kivy.app import App
from kivy.uix.label import Label
if os.name == "nt":
local = "fra"
else:
local = 'fr_FR.UTF-8'
locale.setlocale(locale.LC_ALL,local)
class CalendarApp(App):
def build(self):
# I'm french, I want this to return "janvier" in my app, not "january"
return Label(text=date(2022, 1, 1).strftime('%B'))
if __name__ == "__main__":
app = CalendarApp()
app.run()
I have a simple Kivy app to try out a clickable link opening a Web site. The code is:
kivy.require('1.9.0')
from kivy.app import App
from kivy.uix.label import Label
import webbrowser
class TestApp(App):
def build(self):
ref = '[ref=https://kivy.org/doc/stable/]' + 'Kivy documentation' + '[/ref]'
link = Label(text=ref, markup=True, on_ref_press=self.OpenLink)
return link
def OpenLink(self, label, ref):
webbrowser.open(ref)
if __name__ == '__main__':
TestApp().run()
When I run this app in the Kivy Launcher on Android, tapping the link works and opens the url in the browser. However, when I run the compiled app nothing happens when I tap the link.
In the buildozer.spec file I have:
android.permissions = INTERNET
According to all information I have been able to find, this is all I should need. What else am I missing?
I have tried logging the app using adb logcat but I can't see anything relating to the problem.
I'm planning to use kivy to develop an app related to one of my project. But still I couldn't find a way to make the app run in background and while a certain condition is satisfied I need it to display a push notification in mobile. How can I add push notification feature in kivy? Please let me know if someone know how to make it work. (Note - Even the app is closed in mobile it should run in background..).
I can't tell you how to keep running in the background (because I don't know either) but I can show you how to notify.
by the way,plyer doesn't work as well as windows on android so you should throw with java lib jnius
codes is here:
from kivy.app import App
from kivy.uix.button import Button
from jnius import autoclass
def notify(*args):
AndroidString = autoclass('java.lang.String')
PythonActivity = autoclass('org.kivy.android.PythonActivity')
NotificationBuilder = autoclass('android.app.Notification$Builder')
Context = autoclass('android.content.Context')
Drawable = autoclass('org.test.notify.R$drawable')
icon = Drawable.icon
notification_builder = NotificationBuilder(PythonActivity.mActivity)
notification_builder.setContentTitle(AndroidString('Title'.encode('utf-8')))
notification_builder.setContentText(AndroidString('Message'.encode('utf-8')))
notification_builder.setSmallIcon(icon)
notification_builder.setAutoCancel(True)
notification_service = notification_service = PythonActivity.mActivity.getSystemService(Context.NOTIFICATION_SERVICE)
notification_service.notify(0,notification_builder.build())
class NotifyApp(App):
def build(self):
return Button(text="notify", on_press=notify)
if __name__ == '__main__':
NotifyApp().run()
if you keep getting errors,look here
I am creating an application using Python Kivy that would take the user's input and create an Excel file storing the input.
I tried using openpyxl but the app crashes before starting on my android phone but on a desktop computer, it works perfectly. Is it possible to modify Excel files on my Android phone using Kivy and Openpyxl?
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
import openpyxl
class MyApp(App):
def build(self):
return MyGrid()
class MyGrid(GridLayout):
def __init__(self,**kwargs):
self.submit = Button(text='Submit', font_size=30)
self.submit.bind(on_press=self.pressed2)
self.add_widget(self.submit)
def pressed2(self,instance):
wb = openpyxl.Workbook()
ws = wb.active
ws['A1']='Hello'
wb.save('Trial.xlsx')
if __name__ == "__main__":
MyApp().run()
I use Kivy Launcher and the app crashes but if I remove all openpyxl stuff and put any other function, it works perfectly. I'm expecting it to create an Excel file on my phone. If this is not possible, what can I do instead?
It looks like it's probably a pure python library so it's likely to work without issues on Android, but you'll need to build an APK that actually includes it. It might also turn out that it does have dependencies that are hard to build for some reason, but you'll have to try it to see.
i have a code that loads an image online with the AsyncImage module in kivy. i wrote the code in python3 which runs well on the pc but doesnt work on a packaged apk. i think this is because i packaged it using python2.7 buildozer. thanks an image showing the error in logcat
this is the code
class Gallery(Screen,GridLayout):
scroller = ObjectProperty(None)
grid = ObjectProperty(None)
def __init__ (self,**kwargs):
super(Gallery, self).__init__(**kwargs)
if len(self.ids.grid.children) == 0:
for i in range(13):
src = "http://placehold.it/480x270.png&text=slide-%d&.png" % i
image = MyTile(source=src, allow_stretch=True)
self.ids.grid.add_widget(image)
It seems that your APK is missing ssl support (the URL is redirecting you to an https site...)
try adding:
requirements = kivy,OTHER_STUFF_YOU_NEED,openssl
to your buildozer spec.
EDIT:
as #DipanshuJuneja commented, as of this time the solution works with python2 but not on 3 :(