Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Standalone Android Apps in Python

  • Login to see the comments

Standalone Android Apps in Python

  1. 1. STANDALONE ANDROID APPS IN PYTHON Baptiste Lagarde Sydney Python Group, 2013.11.07 I. Toolchain II. Kivy
  2. 2. JAVA APP VS. PYTHON APP Python cross-compiled for ARM using the Android NDK Android NDK - The Native Development Kit allows you to implement parts of your app using native-code languages such as C and C++.
  3. 3. I. TOOLCHAIN
  4. 4. TOOLCHAIN (1/5) Overview http://python-for-android.readthedocs.org/en/latest/toolchain/
  5. 5. TOOLCHAIN (2/5) Prerequisites ~6GB (sigh) Option A Download Android SDK + NDK Follow pages and pages of Google instructions Download more stuff from inside Eclipse (?!) Set-up some environment variables git clone ..., pip install ... Option B Download .vbi virtual machine image Run with virtualbox
  6. 6. TOOLCHAIN (2/5)
  7. 7. TOOLCHAIN (2/5)
  8. 8. TOOLCHAIN (3/5) Cross-compilation Distribute kv@iyVrulo:/nri/yhnfradod .dsrbt.h- kv iykv-itaBx~adodpto-o-nri$ /itiues m iy 1. Creates a host Python 2. Compiles an ARM Python 3. Opt-in recipes with -m Modules Some Standard Library modules excluded by default to save space Pure python modules can simply be included with the app's code Many modules are available as "recipes"
  9. 9. TOOLCHAIN (4/5) Make Kivy App Kivy - Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. #ts.y etp ipr kv mot iy fo kv.p ipr Ap rm iyap mot p fo kv.i.utnipr Bto rm iyuxbto mot utn casTsApAp: ls etp(p) dfbidsl) e ul(ef: rtr Bto(et'el Wrd) eun utntx=Hlo ol' i _nm_ = '_an_: f _ae_ = _mi_' TsAp)rn) etp(.u( $pto ts.y yhn etp
  10. 10. TOOLCHAIN (5/5) Build and Install Build $c ~adodpto-o-nri/itdfut d /nri/yhnfradodds/eal $.bidp -pcaecmeapemap-nm "yp"-vrin1-dr/aht/iyap /ul.y -akg o.xml.yp -ae MAp -eso -i pt/okv/p/ Install Phone: Settings > Developer options > USB debugging $abisalbnMAp1dbgak d ntl i/yp--eu.p ...or simply open the .apk on the phone (transfer by email, USB, Dropbox, ...)
  11. 11. TOOLCHAIN (5/5)
  12. 12. II. KIVY The KV language Accessing the hardware Useful resources
  13. 13. KIVY (1/5) Example app (Saves the phone's accelerometer readings to CSV)
  14. 14. KIVY (2/5) The KV Language Features Move UI declaration to separate file Root widget Templates Widget classes, inheritance Anything right of ":" is Python! Python imports Event bindings , e.g. on_press Keyword arguments Hooks, e.g. id, root, app, self Bxaot oLyu: oinain "etcl retto: vria" Lbl ae: i:ito d nr TxIpt etnu: i:pt d ah mliie Fle utln: as o_etvldt:apstah) ntx_aiae p.ept( Lbl ae: i:pors d rges Bxaot oLyu: oinain "oiotl retto: hrzna" Bto: utn tx:"tr cpue et Sat atr" o_rs:apsat) npes p.tr( Bto: utn tx:"tpcpue et So atr" o_rs:apso( npes p.tp) Bto: utn tx:"ut et Qi" o_rs:ei( npes xt)
  15. 15. KIVY (3/5) Accessing the hardware with pyjnius 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 >>fo jisipr atcas > rm nu mot uols >>Hrwr =atcas'r.ep.nri.adae) > adae uols(ogrnyadodHrwr' >>Hrwr.ceeoeeEal(re > adaeaclrmtrnbeTu) >>pitHrwr.ceeoeeRaig) > rn adaeaclrmtredn( [.10000906,-.99996271,958016153] 0140005644 0109994323 .30008124 (iOS -> See pyobjus)
  16. 16. KIVY (4/5) Kivy remote shell Useful to try out or troubleshoot hardware-related functions 1. Install Remote Kivy App 2. SSH to a Python prompt 3. Poke around $sh-80 amn121813 s p00 di@9.6.. amn121813spswr:#"iy di@9.6..' asod kv" >>ipr pafr > mot ltom >>pafr.ahn( > ltommcie) 'rvl am7' >>fo jisipr atcas > rm nu mot uols >>TxTSec =atcas'nri.pehtsTxTSec' > etopeh uols(adodsec.t.etopeh) >>PtoAtvt =atcas'r.ep.nri.yhnciiy) > yhnciiy uols(ogrnyadodPtoAtvt' >>ts=TxTSec(yhnciiymciiy Nn) > t etopehPtoAtvt.Atvt, oe >>tssek'el Wrd' TxTSec.UU_LS,Nn) > t.pa(Hlo ol., etopehQEEFUH oe >>tssek'999999,TxTSec.UU_LS,Nn) #hh > t.pa(999999' etopehQEEFUH oe aa
  17. 17. KIVY (5/5) More useful resources 1. Kivy Showcase 2. Kivy Catalog 3. InteractiveLauncher 4. irc.freenode.net #kivy http://www.youtube.com/watch?v=S2sFqFGDu1k
  18. 18. THAT'S ALL References http://python-for-android.readthedocs.org/en/latest/ http://kivy.org/docs/gettingstarted/intro.html http://developer.android.com/tools/sdk/ndk/index.html http://mdqinc.com/blog/2011/09/cross-compiling-python-for-android/
  19. 19. ACTUALLY... I haven't been completely honest Python App gets woken up by Java App Java App stays alive to pass events through JNI

×