приложение вылетает. Такое происходит только на андроиде, а на ПК работает нормально (если функция GPS отключена). Последний экран просто показывает, что нужно, и будет записан в файл Json.
Я не понимаю, почему некоторые кнопки приводят к сбою приложения, а другие нет, хотя все они используют один метод.
есть ли какой-нибудь способ просмотреть код ошибки на Android для отладки моего приложения?
Заранее спасибо
main .py-файл
Код: Выделить всё
from kivy.lang import Builder
from plyer import gps
from kivy.app import App
from kivy.properties import StringProperty
from kivy.clock import mainthread
from kivy.utils import platform
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
import json
import time
Builder.load_file(filename='main.kv')
class GpsMixin():
def start_gps(self) -> None:
gps.start(0,Trailz().MinDistanceSetting)
def stop_gps(self) -> None:
gps.stop()
def Pass(self) -> None:
pass
class GpsRecordingScreen(Screen,GpsMixin):
pass
class GpsPausedScreen(Screen,GpsMixin):
pass
class GpsInfoScreen(Screen,GpsMixin):
pass
class MenuScreen(Screen):
pass
class TestScreen(Screen):
pass
MainScreenManager = ScreenManager()
class Trailz(App):
gps_location = StringProperty()
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self._GPSJsonDict = {'GPSData':{}}
self._jsonTrailPath = "saved_trails/"
self._MinDistancePar = 1
def switch_toSTR(self, screenSTR : str) -> None:
MainScreenManager.switch_to(MainScreenManager.get_screen(screenSTR))
def request_android_permissions(self):
from android.permissions import request_permissions, Permission
def callback(permissions, results):
if all([res for res in results]):
print("callback. All permissions granted.")
else:
print("callback. Some permissions refused.")
request_permissions([Permission.ACCESS_COARSE_LOCATION,Permission.ACCESS_FINE_LOCATION], callback)
def build(self):
global MainScreenManager
MainScreenManager.add_widget(GpsInfoScreen(name='GpsInfoScreen'))
MainScreenManager.add_widget(MenuScreen(name='MenuScreen'))
MainScreenManager.add_widget(GpsRecordingScreen(name='GpsRecordingScreen'))
MainScreenManager.add_widget(GpsPausedScreen(name='GpsPausedScreen'))
MainScreenManager.add_widget(TestScreen(name='TestScreen'))
try:
gps.configure(on_location=self.on_location)
except NotImplementedError:
import traceback
traceback.print_exc()
if platform == "android":
print("gps.py: Android detected. Requesting permissions")
self.request_android_permissions()
return MainScreenManager
def open_gps_recording(self) -> None:
if platform == "ios" or platform == "android":
MainScreenManager.switch_to(MainScreenManager.get_screen('GpsRecordingScreen'))
else:
pass
@mainthread
def on_location(self, **kwargs) -> None:
self._GPSJsonDict['GPSData'][int(time.time()) % 2592000] = kwargs
self.gps_location = '\n'.join([
'{}={}'.format(k, v) for k, v in kwargs.items()])
def Save_GPS_to_json(self) -> None:
if MainScreenManager.get_screen('GpsInfoScreen').ids.GPSNameInput.text != "" and MainScreenManager.get_screen('GpsInfoScreen').ids.GPSDescriptionInput.text != "" and MainScreenManager.get_screen('GpsInfoScreen').ids.GPSMinDistanceInput.text != "":
self._GPSJsonDict['name'] = MainScreenManager.get_screen('GpsInfoScreen').ids.GPSNameInput.text
self._GPSJsonDict['discription'] = MainScreenManager.get_screen('GpsInfoScreen').ids.GPSDescriptionInput.text
self._GPSJsonDict['MinDistance'] = MainScreenManager.get_screen('GpsInfoScreen').ids.GPSMinDistanceInput.text
#with open(str(self._jsonTrailPath + "_".join(MainScreenManager.get_screen('GpsInfoScreen').ids.GPSNameInput.text.split(" ")) + ".json"), "w") as File:
#json.dump(self._GPSJsonDict, File)
MainScreenManager.get_screen('TestScreen').ids.TestLabel.text = str(self._GPSJsonDict)
MainScreenManager.switch_to(MainScreenManager.get_screen('TestScreen'))
@property
def MinDistanceSetting(self) -> int:
return self._MinDistancePar
@property
def GPSJsonDict(self) -> dict:
return self._GPSJsonDict
if __name__ == '__main__':
Trailz().run()
Код: Выделить всё
BoxLayout:
Button:
text: "start trail recording"
on_press: app.open_gps_recording()
:
BoxLayout:
Label:
text: app.gps_location
ToggleButton:
id: StartRecording
text: "start" if self.state == 'normal' else "stop"
on_press:
root.stop_gps() if self.state == 'normal' else root.Pass()
app.switch_toSTR('GpsPausedScreen') if self.state == 'normal' else root.start_gps()
BoxLayout:
Button:
text: "continue"
on_press:
app.switch_toSTR('GpsRecordingScreen')
Button:
text: "stop"
on_press:
app.switch_toSTR('GpsInfoScreen')
GridLayout:
cols: 1
Image:
size_hint: 2, 2
source: 'map.jpeg'
size: self.texture_size
TextInput:
size_hint: 0.3, 0.3
id: GPSNameInput
hint_text: "name"
TextInput:
size_hint: 0.3, 0.3
id: GPSDescriptionInput
hint_text: "description"
TextInput:
size_hint: 0.3, 0.3
id: GPSMinDistanceInput
hint_text: "delta"
Button:
size_hint: 0.3, 0.3
text: "Сохранить"
on_press:app.Save_GPS_to_json()
GridLayout:
cols: 1
Label:
id: TestLabel
text: "None"
Button:
size_hint: 0.3, 0.3
text: "to menu"
on_press: app.switch_toSTR('MenuScreen')
Код: Выделить всё
[app]
title = Trailz
package.name = trailz
package.domain = org.gpstest
source.dir = .
source.include_exts = py,png,jpg,kv,atlas,jpeg
version = 0.1
requirements = python3, kivy, android, https://github.com/HyTurtle/plyer/archive/master.zip
orientation = portrait
osx.python_version = 3
osx.kivy_version = 1.9.1
fullscreen = 0
android.permissions = INTERNET,ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION
android.archs = arm64-v8a, armeabi-v7a
android.allow_backup = True
ios.kivy_ios_url = https://github.com/kivy/kivy-ios
ios.kivy_ios_branch = master
ios.ios_deploy_url = https://github.com/phonegap/ios-deploy
ios.ios_deploy_branch = 1.10.0
ios.codesign.allowed = false
[buildozer]
log_level = 2
warn_on_root = 1
Подробнее здесь: https://stackoverflow.com/questions/792 ... ge-screens
Мобильная версия