Android NDK - The Native Development Kit allows you to implement parts of your app using native-code languages such as C and C++.
Cross-compilation
kivy@kivy-VirtualBox:~/android/python-for-android$ ./distribute.sh -m kivy
Kivy - Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps.
# test.py
import kivy from kivy.app import App from kivy.uix.button import Button class TestApp(App): def build(self): return Button(text='Hello World') if __name__ == '__main__': TestApp().run()
$ python test.py
$ cd ~/android/python-for-android/dist/default
$ ./build.py --package com.example.myapp --name "MyApp" --version 1 --dir /path/to/kivy/app/ debug
$ adb install bin/MyApp-1-debug.apk
BoxLayout: orientation: "vertical" Label: id: intro TextInput: id: path multiline: False on_text_validate: app.setpath() Label: id: progress BoxLayout: orientation: "horizontal"
Button: text: "Start capture" on_press: app.start() Button: text: "Stop capture" on_press: app.stop() Button: text: "Quit" on_press: exit()
pyjnius - Python module to access Java classes as Python classes, using JNI.
JNI - The Java Native Interface is a programming framework that enables Java code running in a Java Virtual Machine to call, and to be called by, native applications and libraries written in other languages
>>> from jnius import autoclass
>>> Hardware = autoclass('org.renpy.android.Hardware')
>>> Hardware.accelerometerEnable(True)
>>> print Hardware.accelerometerReading()
[0.11400000005960464, -0.19099999964237213, 9.5380001068115234]
Kivy remote shell
Useful to try out or troubleshoot hardware-related functions
$ ssh -p8000 admin@192.168.1.3 admin@192.168.1.3's password: # "kivy"
>>> import platform >>> platform.machine() 'armv7l' >>> from jnius import autoclass >>> TextToSpeech = autoclass('android.speech.tts.TextToSpeech') >>> PythonActivity = autoclass('org.renpy.android.PythonActivity') >>> tts = TextToSpeech(PythonActivity.mActivity, None) >>> tts.speak('Hello World.', TextToSpeech.QUEUE_FLUSH, None) >>> tts.speak('999999999999', TextToSpeech.QUEUE_FLUSH, None) # haha
References