Question:
I developed a small testing app that checks both battery status and whether the phone is charging.
The app is running locally from python main.py
, but when I install it in Android Studio emulator , the software starts and closes.
Update
The Android package is being generated with buildozer
buildozer.spec (settings only)
[app]
title = My Test
package.name = mytest
package.domain = org.test
source.dir = .
source.include_exts = py,png,jpg,kv,atlas
source.exclude_exts = spec
version = 0.1
requirements = python3, kivy==2.0.0, kivymd==0.104.1, sdl2_ttf == 2.0.15
icon.filename = %(source.dir)s/data/icon.png
orientation = portrait
osx.python_version = 3
osx.kivy_version = 1.9.1
fullscreen = 0
android.permissions = BATTERY_STATS
android.arch = armeabi-v7a
[buildozer]
log_level = 2
warn_on_root = 1
End of update
I understand that the problem is when I use kivimd , with kivy it worked.
follow the code
mytest.kv
#:import MDLabel kivymd.uix.label
#:import MDBoxLayout kivymd.uix.boxlayout
#:import MDFloatLayout kivymd.uix.floatlayout
#:import MDTextButton kivymd.uix.button
<Page>:
lbl1: lbl1
lbl2: lbl2
MDFloatLayout:
MDTextButton:
center: root.center
size_hint_y: None
pos_hint: {'y': .5}
text: "Battery Status"
on_press: root.get_status()
MDBoxLayout:
size_hint_y: None
pos_hint: {'y': .1}
MDLabel:
text: "Is Charging?"
MDLabel:
id: lbl1
text:
MDLabel:
text: "Percentage"
MDLabel:
id: lbl2
text:
main.py
from kivymd.app import MDApp
from kivymd.uix.boxlayout import MDBoxLayout
from plyer import battery
class Page(MDBoxLayout):
def get_status(self, *args):
self.lbl1.text = str(battery.status['isCharging'])
self.lbl2.text = str(battery.status['percentage']) + "%"
class MyTest(MDApp):
def build(self):
return Page()
def on_pause(self):
return True
if __name__ == "__main__":
app = MyTest()
app.run()
Note : Substituting from kivymd
to kivy
and substituting from MD to , works.
If you need more information, please comment on the post.
Answer:
I had the same problem: a simple application that didn't work on android with kivymd, but that worked with kivy. I managed to solve the problem by changing the requirements in buildozer.spec (according to the kitchen_sink demo on github):
requirements = python3,kivy==2.0.0,https://github.com/kivymd/KivyMD/archive/master.zip,certifi,pillow
Where it is commented: "(str) Custom source folders for requirements. Sets custom source for any requirements with recipes" uncomment and change from kivy to kivymd:
requirements.source.kivymd = ../../kivymd