I am trying to develop a simple app that uses google translate's API. The app builds and installs correctly, but when I open the app on my phone, it just crashes, without any kind of error message.
This is my main.py file:
import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
from kivy.graphics import Color, Rectangle
from googletrans import Translator
Window.clearcolor = (0.2, 0.2, 0.2, 1)
Window.size = (450, 800)
tr = Translator()
# class in which we are defining action on click
class RootWidget(BoxLayout):
def translate(self, text, src, dest):
print(text, src, dest)
if text != "":
self.output_text.text = tr.translate(text, src=src, dest=dest).text
def speak(self):
print('speaking')
def read(self):
print('reading')
class TranslatorApp(App):
def build(self):
return RootWidget()
myApp = TranslatorApp()
myApp.run()
This is my translator.kv file:
<RootWidget>:
input_text:input_text
output_text:output_text
src_lang:src_lang
dest_lang:dest_lang
BoxLayout:
orientation: 'vertical'
spacing: 5
padding: 5
BoxLayout:
orientation: 'horizontal'
spacing: 5
size_hint: [1, 0.1]
Label:
text: 'Texto a traducir'
halign: 'left'
Label:
text: 'Texto traducido'
halign: 'left'
BoxLayout:
orientation: 'horizontal'
spacing: 5
size_hint: [1, 0.9]
TextInput:
id: input_text
color: [180, 180, 180]
size_hint: [0.5, 1]
TextInput:
id: output_text
text: "s"
color: [180, 180, 180]
size_hint: [0.5, 1]
BoxLayout:
orientation: 'horizontal'
spacing: 5
size_hint: [1, 0.2]
Button:
text: 'Hablar'
color: [0, 255, 255, .67]
background_normal: ''
background_color: [0, 0.5, 1, .85]
on_press: root.speak()
size_hint: [0.5, 1]
Button:
text:'Traducir'
color: [0, 255, 255, .67]
background_normal: ''
background_color: [1, 1, 1, 0.7]
on_press: root.translate(input_text.text, src_lang.text, dest_lang.text)
size_hint: [0.5, 1]
BoxLayout:
orientation: 'vertical'
spacing: 5
BoxLayout:
orientation: 'horizontal'
spacing: 5
Label:
text: 'Idioma de\norigen'
halign: 'left'
Label:
text: 'Idioma de\ndestino'
halign: 'left'
BoxLayout:
orientation: 'horizontal'
spacing: 5
TextInput:
id: src_lang
text: 'es'
TextInput:
id: dest_lang
text: 'en'
Button:
text: 'Leer traducción'
on_press: root.read()
I run the command buildozer android debug
to build the app.
I am aware that there is android_new
for the new p4a toolchain, but when I try that I get an error message like this:
Unknown command/target android_new
I would add the buildozer.spec file but stackoverflow thinks it is spam
I feel dumb answering my own question.
I had added googletrans
to the spec file, so I thought that wasn't the problem. On one of my attempts to fix the problem, I updated the module, and I saw there were some depencencies for googletrans
and all I needed to do was to add those dependencies to the requirements too