Kivy-android app crashes
I am writing a mobile translator in python kivy. I use the Yandex API. When compiled on windows, the application works correctly. When trying to run on android-crashes after the "Loading" screen saver. How can this be fixed?
Here is my code:
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
import requests
URL_AUTH = 'https://translate.yandex.net/api/v1.5/tr.json/getLangs?'
URL_TRANSLATE = 'https://translate.yandex.net/api/v1.5/tr.json/translate'
KEY = '[API ключ]'
LANG = 'en-ru'
# --- Запрос перевода текста
auth = requests.post(URL_TRANSLATE, data={'key': KEY, 'text': 'Translate', 'lang': LANG, }).text
# --- Приложение
class translator(App):
def translate(self, instance):
# --- Запрос перевода текста
auth = requests.post(URL_TRANSLATE, data={'key': KEY, 'text': input_text.text, 'lang': LANG, }).text
print(auth)
# --- Обновление текста в Label
self.output_text.text = str(auth)
def build(self):
al = AnchorLayout()
bl = BoxLayout(orientation='vertical', size_hint=[0.9, 0.9])
btn = Button(text='Перевести', on_press=self.translate)
global input_text
input_text = TextInput(multiline=False, text='Введите текст')
self.output_text = Label(text=auth)
bl.add_widget(input_text)
bl.add_widget(self.output_text)
bl.add_widget(btn)
al.add_widget(bl)
return al
# --- Запуск приложения
if __name__ == '__main__':
translator().run()
0
Author: Suvitruf - Andrei Apanasik, 2020-03-09
1 answers
Turn on the developer mode on the phone, connect to the PC, if buildozer is on a virtual machine, then throw the usb port there, go to the project directory in the terminal, enter buildozer android logcat, first in the buildozer.spec file, uncomment the line " #android. logcat_filters = *: S python:D", run the app on your phone to see the log why it crashes.
1
Author: palamiko, 2020-03-13 11:20:10