Исползую базовый код на python kivy:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
class MainApp(App):
def build(self):
self.operators = ["/", "*", "+", "-"]
self.last_was_operator = None
self.last_button = None
main_layout = BoxLayout(orientation="vertical")
self.solution = TextInput(
multiline=False, readonly=True, halign="right", font_size=55
)
main_layout.add_widget(self.solution)
buttons = [
["7", "8", "9", "/"],
["4", "5", "6", "*"],
["1", "2", "3", "-"],
[".", "0", "C", "+"],
]
for row in buttons:
h_layout = BoxLayout()
for label in row:
button = Button(
text=label,
pos_hint={"center_x": 0.5, "center_y": 0.5},
)
button.bind(on_press=self.on_button_press)
h_layout.add_widget(button)
main_layout.add_widget(h_layout)
equals_button = Button(
text="=", pos_hint={"center_x": 0.5, "center_y": 0.5}
)
equals_button.bind(on_press=self.on_solution)
main_layout.add_widget(equals_button)
return main_layout
def on_button_press(self, instance):
current = self.solution.text
button_text = instance.text
if button_text == "C":
# Очистка виджета с решением
self.solution.text = ""
else:
if current and (
self.last_was_operator and button_text in self.operators):
# Не добавляйте два оператора подряд, рядом друг с другом
return
elif current == "" and button_text in self.operators:
# Первый символ не может быть оператором
return
else:
new_text = current + button_text
self.solution.text = new_text
self.last_button = button_text
self.last_was_operator = self.last_button in self.operators
def on_solution(self, instance):
text = self.solution.text
if text:
solution = str(eval(self.solution.text))
self.solution.text = solution
if __name__ == "__main__":
app = MainApp()
app.run()
Когда пытаюсь скомпилировать код под Android вылезает ошибка:
Traceback (most recent call last):
File "/usr/local/bin/buildozer", line 9, in <module>
load_entry_point('buildozer==0.27', 'console_scripts', 'buildozer')()
File "/usr/local/lib/python2.7/dist-packages/buildozer/scripts/client.py", line 13, in main
Buildozer().run_command(sys.argv[1:])
File "/usr/local/lib/python2.7/dist-packages/buildozer/__init__.py", line 980, in run_command
self.target.run_commands(args)
File "/usr/local/lib/python2.7/dist-packages/buildozer/target.py", line 85, in run_commands
func(args)
File "/usr/local/lib/python2.7/dist-packages/buildozer/target.py", line 95, in cmd_debug
self.buildozer.prepare_for_build()
File "/usr/local/lib/python2.7/dist-packages/buildozer/__init__.py", line 161, in prepare_for_build
self.target.install_platform()
File "/usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py", line 424, in install_platform
self._install_android_packages()
File "/usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py", line 383, in _install_android_packages
ver = self._find_latest_package(packages, 'build-tools-')
File "/usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py", line 349, in _find_latest_package
version = self._process_version_string(version_string)
File "/usr/local/lib/python2.7/dist-packages/buildozer/targets/android.py", line 318, in _process_version_string
version = [int(i) for i in version_string.split(".")]
ValueError: invalid literal for int() with base 10: '0-preview'
Сам код на windows 10 работает отлично:
Как мне правильно скомпилировать код под android что-бы небыло ошибки?
Используюю образ линукса от разрботчиков kivy -buildozer. Запускаю на virtual box.
Зарание благодорю!