Android: The Land that Python Forgot? (Christopher Neugebauer)

Android: The Land that Python Forgot? (Christopher Neugebauer)

Presented at PyCon Canada, 10 August 2013

We all know that Python is the best language there is, right? Well, we Pythonistas might know that, but the world of Mobile development has passed Python by. Apple's iOS platform and Google's Android platform have chosen Objective-C and Java respectively as their preferred languages. Alternative toolkits exist, some of them even based on Python, but the pursuit of the perfect native experience has left the best apps developers using the official languages for their chosen platform.

This talk draws on my experience as a Python native who has found himself developing exclusively for Android. We'll look at the current state of Android development -- how it works in general, and those areas where Python is already a viable option. We'll finish off by finding low-hanging fruit in the quest for making Python a first-class language for building Android apps.

3b085ba94fee217d7656971b0cb4cf00?s=128

PyCon Canada

August 10, 2013
Tweet

Transcript

  1. Saturday, 10 August 13

  2. Android The Land that Python Forgot? Christopher Neugebauer PyCon Canada

    10 August 2013 chris.neugebauer.id.au chrisjrn@gmail.com @chrisjrn Saturday, 10 August 13 Hi! Today I’m here to talk to you about the state of Python on Android. My name’s Chris, feel free to contact me through the details on this slide. Tweet frequently, please!
  3. Hello! Saturday, 10 August 13 HI! I’d like to thank

    PyCon Canada for the opportunity to present...
  4. PY I♥ Saturday, 10 August 13 Now, we’re at a

    PyCon, so I I imagine everyone here is part of the Python community somehow. And we all love Python enough to give up a weekend to attend a conference about Python...
  5. Why do we use Python? Saturday, 10 August 13 To

    find out why people use Python, I conducted an extensive survey, in an entirely scientific manner.
  6. Saturday, 10 August 13 I asked everyone on twitter to

    tell me why they use Python.
  7. Saturday, 10 August 13 It turns out there a lot

    of reasons why people use Python. <CLICK> Some people like the range of Libraries. <CLICK> Some people are fans of the Syntax <CLICK> People value having ready access to Documentation <CLICK> The strong sense of Community that comes with using Python <CLICK> Some people like the sense of Productivity that Python instils in them <CLICK> And others value the Simplicity of the language.
  8. Saturday, 10 August 13 It turns out there a lot

    of reasons why people use Python. <CLICK> Some people like the range of Libraries. <CLICK> Some people are fans of the Syntax <CLICK> People value having ready access to Documentation <CLICK> The strong sense of Community that comes with using Python <CLICK> Some people like the sense of Productivity that Python instils in them <CLICK> And others value the Simplicity of the language.
  9. Saturday, 10 August 13 It turns out there a lot

    of reasons why people use Python. <CLICK> Some people like the range of Libraries. <CLICK> Some people are fans of the Syntax <CLICK> People value having ready access to Documentation <CLICK> The strong sense of Community that comes with using Python <CLICK> Some people like the sense of Productivity that Python instils in them <CLICK> And others value the Simplicity of the language.
  10. Saturday, 10 August 13 It turns out there a lot

    of reasons why people use Python. <CLICK> Some people like the range of Libraries. <CLICK> Some people are fans of the Syntax <CLICK> People value having ready access to Documentation <CLICK> The strong sense of Community that comes with using Python <CLICK> Some people like the sense of Productivity that Python instils in them <CLICK> And others value the Simplicity of the language.
  11. Saturday, 10 August 13 It turns out there a lot

    of reasons why people use Python. <CLICK> Some people like the range of Libraries. <CLICK> Some people are fans of the Syntax <CLICK> People value having ready access to Documentation <CLICK> The strong sense of Community that comes with using Python <CLICK> Some people like the sense of Productivity that Python instils in them <CLICK> And others value the Simplicity of the language.
  12. Saturday, 10 August 13 It turns out there a lot

    of reasons why people use Python. <CLICK> Some people like the range of Libraries. <CLICK> Some people are fans of the Syntax <CLICK> People value having ready access to Documentation <CLICK> The strong sense of Community that comes with using Python <CLICK> Some people like the sense of Productivity that Python instils in them <CLICK> And others value the Simplicity of the language.
  13. Saturday, 10 August 13 It turns out there a lot

    of reasons why people use Python. <CLICK> Some people like the range of Libraries. <CLICK> Some people are fans of the Syntax <CLICK> People value having ready access to Documentation <CLICK> The strong sense of Community that comes with using Python <CLICK> Some people like the sense of Productivity that Python instils in them <CLICK> And others value the Simplicity of the language.
  14. Yay Python! Saturday, 10 August 13 With these credentials, Python

    should really be the language that everyone uses wherever they can. Indeed, Python’s widely used on the Web, in Science, in Infrastructure, in Desktop Apps.
  15. Mobile (it’s a thing) Saturday, 10 August 13

  16. Fact: Python Developers don’t care about Mobile. Saturday, 10 August

    13 At present, Python developers don’t consider Mobile as a field that’s worth devoting their development time towards.
  17. Fact: Mobile Developers don’t care about Python. Saturday, 10 August

    13 Of more concern, people who want to develop mobile apps don’t consider Python as an option for producing apps.
  18. WHY? Saturday, 10 August 13

  19. Today 1. Mobile (wat); Android 2. Apps: What even is

    it? 3. Python on Android: Lost cause? Saturday, 10 August 13 I’m going to start off by looking at the field of Mobile computing as it stands, and specifically at Android. Why people care about Android, and what makes it different from other platforms out there. I’m going to look at what constitutes an app in the world of Mobile. Finally, I’m going to survey the landscape of Python on Android.
  20. Today 1. Why don’t people use Python on Android? 2.

    What’s already out there? 3. What can we do about it? Saturday, 10 August 13 In doing so, I hope to answer these questions: - Why aren’t people using Python to make Android apps? - How much can we actually do with Python on Android? - How can we improve the situation?
  21. About me Australian Saturday, 10 August 13 And before I

    get started properly -- I’m Australian. Apologies if I use any strange words. If you have any difficulties understanding me, I offer translation services for a small fee.
  22. About me Python native Saturday, 10 August 13 I’m a

    Python native
  23. About me Python native (on-and-off since 2004) Saturday, 10 August

    13 I’ve been using Python somewhat actively for the best part of 9 years now.
  24. About me Python native Co-chair, PyCon Australia 2012 & 2013

    (Hobart, Tasmania) Saturday, 10 August 13 Co-chaired PyCon Australia, which ran last month in Hobart.
  25. About me Professional Android dev since 2010 Saturday, 10 August

    13 As much as I like Python, I’ve found myself doing Android app development professionally since 2010.
  26. About me Professional Android dev since 2010 (Have not coded

    Python professionally since 2010) Saturday, 10 August 13 And this means that I’ve not coded a substantial project in Python for close to three years now. <CLICK> this makes me sad.
  27. About me Professional Android dev since 2010 (Have not coded

    Python professionally since 2010) :( Saturday, 10 August 13 And this means that I’ve not coded a substantial project in Python for close to three years now. <CLICK> this makes me sad.
  28. 1. Android What even is it? Why do people use

    it? Why should we care? Saturday, 10 August 13 So, let’s set the stage. What is Android? Why is it important? And why should we as Python developers care about making apps for Android?
  29. Mobile Saturday, 10 August 13 So let’s start by looking

    at what Mobile computing is...
  30. Saturday, 10 August 13 This is the first phone I

    owned. It’s a Nokia 5110. It had a 4 line black and white screen, it was quite heavy, and it had a funny external antenna that meant it didn’t quite fit in your pocket. <CLICK>
  31. • Telephone • SMS • Saturday, 10 August 13 Whilst

    not remarkable by today’s standards -- it made calls, it could send texts And most importantly, it had the first thing I can recognise as an app -- <CLICK> snake. It was a simple game that I could pick up randomly on the bus
  32. • Telephone • SMS • • Telephone • SMS •

    Snake Saturday, 10 August 13 Whilst not remarkable by today’s standards -- it made calls, it could send texts And most importantly, it had the first thing I can recognise as an app -- <CLICK> snake. It was a simple game that I could pick up randomly on the bus
  33. Saturday, 10 August 13 A few years after that one,

    the first “smart” phones started coming out. But these phones didn’t have anything that I think resembles today’s mobile apps -- they instead tried to resemble cut-down versions of desktop apps. - Large keyboard - Stylus -- basically mouse interaction Not something a consumer would want. Great if you want lots of e-mail, etc.
  34. Saturday, 10 August 13 This was the first real phone

    that looks like the mobile devices we’re used to these days. It’s the Apple iPhone. <CLICK>
  35. • 2007 • 2008 for apps Saturday, 10 August 13

    The phone itself? It only showed up in 2007. The iPhone only became an app development platform in 2008. So when we talk about Mobile development, we’re dealing with a field that’s barely 5 years old.
  36. 2008 Saturday, 10 August 13 Android also came out in

    2008. So when we talk about Android, we’re talking about a ideas that’s are about as old as the iPhone. And because of this, Android and iOS’s development has influenced each others’ design decisions. But what is Android exactly?
  37. It’s an operating system Saturday, 10 August 13 At its

    simplest, Android is an Operating System...
  38. It’s an operating system for phones Saturday, 10 August 13

    It runs on smartphones...
  39. It’s an operating system for tablets Saturday, 10 August 13

    Tablet devices...
  40. It’s an operating system for your sunglasses Saturday, 10 August

    13 ... with Google Glass, it even runs on Sunglasses.
  41. Gartner, 14 May 2013 Saturday, 10 August 13 Android’s also

    very widely deployed -- 156 million Android phones were sold in the first quarter of this year, which made up 75% of all smartphone sales...
  42. 0 50 100 150 200 Full-size computers Android devices Millions

    of Units, Q1 2013 Gartner, 10 April 2013; 14 May 2013 Saturday, 10 August 13 ... and for a more startling context: Android phones alone are now outselling full size computers at a rate of 2:1 -- sales of traditional computers are slowing at an unprecedented rate. So, not caring about Android is not caring about what is by far the fastest-growing end-user operating system currently out there.
  43. Different form Different concerns Saturday, 10 August 13 Mobiles are

    smaller than full-size computers. Obviously. But, as well as having a different form factor, there’s a key difference between Mobiles and Full-Size computers: People use them when they’re mobile.
  44. Task-Oriented Saturday, 10 August 13 People use mobiles for tasks

    that are immediately important -- in the short term. That means good mobile apps should make it quick and easy to solve tasks... and then get out of the way. Mobiles need a low cognitive load -- you use them when you’re interacting with the real world. Your users might be walking across a street, or driving a car. Ideally you want to distract people for the minimum amount of time...
  45. (low concentration threshold) Saturday, 10 August 13 ... Lest a

    traffic accident happen.
  46. Saturday, 10 August 13 Screens are small, and pointers are

    ultra-low precision compared with a mouse. UI layouts need to be optimised for the screen being totally occluded by your thumb (this is VERY different to stylus touch screens)
  47. Saturday, 10 August 13 Apps have a consistent design language

    -- key features go in similar places. Even if apps do different things, and look different overall, information gets communicated in a visually similar way. (Android: Action Bar; Font Weights, etc) Consistency of UI elements reduces cognitive load, and makes it easier to learn the important or differentiating features of an app. Learning an unusual UI scheme makes an app more distracting -- less useful when you’re mobile.
  48. Saturday, 10 August 13 Visual design is usually treated as

    part of the development process than you may otherwise be familiar with. <CLICK> For Android, the developer guides give equal prominence to how you should design and lay things out visually, along with how you implement them in code.
  49. Saturday, 10 August 13 Visual design is usually treated as

    part of the development process than you may otherwise be familiar with. <CLICK> For Android, the developer guides give equal prominence to how you should design and lay things out visually, along with how you implement them in code.
  50. Apps that form an ecosystem Saturday, 10 August 13 Especially

    on Android, big apps with lots of features are frowned upon. The best Android apps are small -- they solve a single task. They get launched from within other apps. When other apps can solve a task for them, they launch those apps. As an example <CLICK>
  51. Capture Organise Share Saturday, 10 August 13 Android has an

    image management system -- so the camera provides the facility for image capture. The gallery is used for organising images. And then the system provides an API for sharing images. The Gallery doesn’t need to know what precisely what apps can receive images -- apps just make that feature available. This is using a native API *TO MAKE THINGS EASIER TO LEARN*
  52. Curated software distribution Saturday, 10 August 13 Possibly the most

    important hallmark of modern Mobile devices is having curated software distribution.
  53. Emphasis on native Saturday, 10 August 13 The emphasis of

    software curation is to produce software that natively targets a given system. <CLICK>
  54. Emphasis on native The web is secondary Saturday, 10 August

    13 What should concern Python programmers is that the web is very much a secondary experience on Mobile devices.
  55. Saturday, 10 August 13 Just to clarify this: here’s a

    marketing photo of one of Google’s flagship Android devices. It has a bunch of apps shown prominently on the home screen. <CLICK> Let’s take a look at them.
  56. Saturday, 10 August 13 <CLICK> The first one is a

    web browser -- so the web is pretty important. <CLICK> But then every other app is for a product that already has a pretty good Mobile Web site. <CLICK> And the last one?
  57. Saturday, 10 August 13 <CLICK> The first one is a

    web browser -- so the web is pretty important. <CLICK> But then every other app is for a product that already has a pretty good Mobile Web site. <CLICK> And the last one?
  58. Saturday, 10 August 13 <CLICK> The first one is a

    web browser -- so the web is pretty important. <CLICK> But then every other app is for a product that already has a pretty good Mobile Web site. <CLICK> And the last one?
  59. Saturday, 10 August 13 <CLICK> The first one is a

    web browser -- so the web is pretty important. <CLICK> But then every other app is for a product that already has a pretty good Mobile Web site. <CLICK> And the last one?
  60. Saturday, 10 August 13 Well, the point of that one

    is to help you find more of the apps that have been written specifically for Android.
  61. Saturday, 10 August 13 Another important pattern is that native

    apps know when to take over from the web if they can provide a native experience for a URL. When you ask for a geo-location, Google Earth and Google Maps know they can provide a native experience. When you ask for a YouTube video, the YouTube app offers to take over for you.
  62. Saturday, 10 August 13 People want to use Mobile devices

    because they’re mobile. Most of the tasks that people want to solve involve being connected to a network. But Mobile networks come with their own set of problems -- they’re inherently unreliable.
  63. Saturday, 10 August 13 Users can store themselves in faraday

    cages;
  64. Saturday, 10 August 13 Users use their devices on public

    transport, and put themselves through blackspots like tunnels and crowded places like the city centre
  65. Saturday, 10 August 13 Or they could just voluntarily lock

    themselves into an unreliable network.
  66. Resilience is key Saturday, 10 August 13 Your app should

    not break if you drop a few packets; and you need to make sure that your app works to some extent even if you can’t get on a network at all.
  67. Low-Effort UI + Native Ecosystem + Network Resilience = Android

    UX Saturday, 10 August 13 In combination, the three things that I’ve talked about - a UI that’s easy to learn, - fitting in with other apps on the system when you can - being usable even if you’re in a failure case
  68. Low-Effort UI + Native Ecosystem + Network Resilience = Android

    UX Saturday, 10 August 13 These things *in concert* are what we refer to as UX.
  69. Programming for Android Saturday, 10 August 13 To cap this

    section off, let’s quickly look at how you write code for Android, the “official” way We get to start off with some fantastic news... <CLICK>
  70. Saturday, 10 August 13 Android apps are written in Java.

    <CLICK> which is very exciting. So let’s see how developing Java on Android differs from writing Python...
  71. (Yay) Saturday, 10 August 13 Android apps are written in

    Java. <CLICK> which is very exciting. So let’s see how developing Java on Android differs from writing Python...
  72. Write in Python Execute on CPython VM Saturday, 10 August

    13 When you write programs in Python, you simply write some code, and you can immediately execute that code with a Python interpreter. As far as you (the user) are concerned, there’s no separate compilation phase. <CLICK> It’s worth considering that the machine on which you develop for Python can be the same machine as you run your code on. If it isn’t, then we’re going to call the machine you run the code on the “target”.
  73. Write in Python Execute on CPython VM development environment target

    device Saturday, 10 August 13 When you write programs in Python, you simply write some code, and you can immediately execute that code with a Python interpreter. As far as you (the user) are concerned, there’s no separate compilation phase. <CLICK> It’s worth considering that the machine on which you develop for Python can be the same machine as you run your code on. If it isn’t, then we’re going to call the machine you run the code on the “target”.
  74. Write in Java Compile to JVM Bytecode Execute on Java

    VM Saturday, 10 August 13 With Java, there’s a second step in the middle: you compile your code to JVM Bytecode, which can then be executed on a Java VM. The compilation phase happens BEFORE you run your code, and <CLICK> cannot typically happen on the target.
  75. Write in Java Compile to JVM Bytecode Execute on Java

    VM dev env target Saturday, 10 August 13 With Java, there’s a second step in the middle: you compile your code to JVM Bytecode, which can then be executed on a Java VM. The compilation phase happens BEFORE you run your code, and <CLICK> cannot typically happen on the target.
  76. Dalvik Saturday, 10 August 13 Android does things a little

    differently. Android doesn’t use the JVM. It uses a low-level virtual machine called Dalvik. Dalvik doesn’t use Java Bytecode either. It has its own bytecode format.
  77. Write in Java Compile to JVM Bytecode Execute on Dalvik

    VM ??? Saturday, 10 August 13 So you write code in Java, and use the normal Java toolchain to produce an executable. But how do you get that to run on Dalvik? <CLICK>
  78. Write in Java Compile to JVM Bytecode Execute on Dalvik

    VM Convert to Dalvik Bytecode Saturday, 10 August 13 The Android SDK provides a convertor. It takes JVM bytecode, and produces Dalvik bytecode from that. This basically means that you as a developer simply see the Java toolchain, and once you have code ready to deploy, you convert it to Dalvik format. <CLICK> Important: the conversion phase MUST happen on the device you’re developing on. It doesn’t happen on the device.
  79. Write in Java Compile to JVM Bytecode Execute on Dalvik

    VM Convert to Dalvik Bytecode dev env target Saturday, 10 August 13 The Android SDK provides a convertor. It takes JVM bytecode, and produces Dalvik bytecode from that. This basically means that you as a developer simply see the Java toolchain, and once you have code ready to deploy, you convert it to Dalvik format. <CLICK> Important: the conversion phase MUST happen on the device you’re developing on. It doesn’t happen on the device.
  80. Saturday, 10 August 13 In particular, this means that you

    have something that looks like Java to a developer... <CLICK> ... but for which everything we know about Java infrastructure on a low level is wrong. Isn’t that exciting?
  81. Saturday, 10 August 13 In particular, this means that you

    have something that looks like Java to a developer... <CLICK> ... but for which everything we know about Java infrastructure on a low level is wrong. Isn’t that exciting?
  82. Android • Mobile: Probably kinda important • Android: Also important

    • Android Coding: Java, but not as we know it. Saturday, 10 August 13 So by now, you know a tiny bit about the landscape of mobile, and where android fits into it. You also now know that I spend my working hours writing Java code --- but this Java code is a front-end for writing Dalvik code, and not for running on Java infrastructure.
  83. 2. Apps. Saturday, 10 August 13 And now that we

    know about Android, what it is, why people care, and how you’re meant to code for it... Let’s look at the defining feature of Mobile these days -- Apps. In particular, we’ll look at ways that you can code them
  84. Three Types Saturday, 10 August 13 There are basically three

    ways you can go about making an app that runs on Android: <CLICK>
  85. Three Types • Mobile Web • Semi-Native • Native Saturday,

    10 August 13 The first -- and probably the most readily accessible to people in this room -- is the Mobile Web. The second is to make apps that deploy onto Android, but aren’t written with Android in mind. I’m going to call these “Semi-Native” apps. The last is to write apps that are developed with Android entirely in mind. These are what I mean when I refer to “native” apps.
  86. Mobile Web Saturday, 10 August 13 So, the least native

    way to target a mobile device is to produce a mobile web app.
  87. Saturday, 10 August 13 And that’s basically because the Mobile

    Web is basically the web that you’ve been coding for since forever, but now it runs on Mobile devices.
  88. Saturday, 10 August 13 So if you have a complicated

    web app, that’s backed by Python then all you really need to do is make sure that your UI works well on a small screen.
  89. Saturday, 10 August 13 And HTML5 has a lot of

    features that make developing mobile web apps possible: - Geolocation APIs - Offline web apps - Client-side storage
  90. Saturday, 10 August 13 And indeed, the features in HTML5

    were so good back in 2007, that this was the official way to create apps when the iPhone launched. <CLICK> Steve Jobs “You will be very surprised and pleased at how these applications look and work on iPhone” But for a final word on that... let’s see what happened 9 months later: <CLICK>
  91. “Developers and users alike are going to be very surprised

    and pleased at how great these applications look and work on iPhone,” Steve Jobs, 11 June, 2007 Saturday, 10 August 13 And indeed, the features in HTML5 were so good back in 2007, that this was the official way to create apps when the iPhone launched. <CLICK> Steve Jobs “You will be very surprised and pleased at how these applications look and work on iPhone” But for a final word on that... let’s see what happened 9 months later: <CLICK>
  92. Saturday, 10 August 13 “Apple announces iPhone 2.0 -- Now

    with SDK!” It didn’t take developers -- and Apple -- long to realise that there were interesting features to bring to users. <CLICK> So let’s take a look at a couple of reasons why web apps might not be
  93. “The SDK will allow developers to create … applications that

    leverage the iPhone’s … user interface, animation, storage, accelerometer” Apple, 6 March 2008 Saturday, 10 August 13 “Apple announces iPhone 2.0 -- Now with SDK!” It didn’t take developers -- and Apple -- long to realise that there were interesting features to bring to users. <CLICK> So let’s take a look at a couple of reasons why web apps might not be
  94. Look & Feel Very non-native Saturday, 10 August 13 Mobile

    apps design is very much about replicating the look and feel of the OS -- pick a few native apps at random, and you’ll almost certainly see common design elements. On the other hand, the web doesn’t really provide you with elements to fit in with *any* design framework, let alone that of a particular mobile OS. If you want your mobile web app to look native on any given platform, you’ll need to do extra work.
  95. Saturday, 10 August 13 Going to the effort of making

    a mobile web app look native for one platform can often mean that that the app looks out of place on another. The official PyCon Canada web app is laid out a lot like an iPhone app, and doesn’t look like it belongs on Android.
  96. Saturday, 10 August 13 Installing a web app normally involves

    a navigating through a browser and saving a bookmark. This isn’t how people normally find software on Mobile devices. Indeed, you can’t find the PyCon Canada app on the play store -- the only way to find it is to know what the URL for the app is. This limits your exposure.
  97. Saturday, 10 August 13 Installing a web app normally involves

    a navigating through a browser and saving a bookmark. This isn’t how people normally find software on Mobile devices. Indeed, you can’t find the PyCon Canada app on the play store -- the only way to find it is to know what the URL for the app is. This limits your exposure.
  98. Saturday, 10 August 13 Installing a web app normally involves

    a navigating through a browser and saving a bookmark. This isn’t how people normally find software on Mobile devices. Indeed, you can’t find the PyCon Canada app on the play store -- the only way to find it is to know what the URL for the app is. This limits your exposure.
  99. Saturday, 10 August 13 Mobile devices are subject to different

    network conditions -- if you’ve accessed a web site on a laptop, you’re almost certainly going to have network access for as long as you’re using that site. If you’re on a mobile device, if you hit a site once, you have no guarantee that the network will stay fast, if the network will stay up long enough to finish a request, or even if the network will remain the same. (Switch to wifi?) This is important <click>
  100. Network access defines structure Saturday, 10 August 13 because on

    the web, the entire structure of your app is determined by accessing the network: click a link? That’s a new HTTP request. If you pull down a new page with every link, and that page pulls down all of its UI on every load, then your site will suck on a mobile network. So making a web app that works on mobile is as much about making sure your app works offline, as it is making sure it’s usable from an interface perspective. (PyCon Canada app is actually pretty good here)
  101. Python for Mobile Web? Saturday, 10 August 13 So you

    might be wondering that the status is with Python and mobile web.
  102. Solved Saturday, 10 August 13 It’s basically a solved problem...

  103. Solved (if you can tolerate JS) Saturday, 10 August 13

    ... or as solved as it is on the desktop browser, and we seem to be able to tolerate that. If you’re producing a web app with Django on the back-end, you don’t have to do anything extra to make it work for mobile devices. That’s all front-end stuff.
  104. Semi-Native Saturday, 10 August 13 The second kind of app

    I want to look at are “semi-native” apps...
  105. Saturday, 10 August 13 Semi-native apps are apps that you

    can find on the Play Store (or the App store on iPhone), but they’re written for a cross-platform toolkit, and so aren’t written with Android specifically in mind.
  106. Often just HTML5 + niceness Saturday, 10 August 13 The

    more popular Open Source frameworks for doing this are PhoneGap (Adobe) Appcelerator Titanium Both just a way of packaging HTML5+JS apps -- this solves the problem of apps dropping off the network -- most of the UI is already on the device. (Likewise, this is a good way to wrap a web browser so you can list a web app on the Play store)
  107. Saturday, 10 August 13 They also do a semi-OK version

    of smoothing over the major UI differences between the two platforms... in this case, mostly just swapping the positioning of some UI elements. As is pretty clear here, the Android app looks a LOT like an iOS app, and this is pretty standard across these sorts of frameworks. You get apps that are pretty good on one platform, acceptable on another, but not great on either.
  108. ProcessCraft BPMN Saturday, 10 August 13 The alternative to HTML+JS

    cross-platform libraries is to use something that provides its own set of widgets and style. This screenshot is of an app that’s running on Android, but it definitely doesn’t look like an Android app. This gives you a greater choice of language, and takes you further away from the native experience. This is not necessarily something you want either.
  109. Exception: Games. Saturday, 10 August 13 The one case where

    you don’t care whether your app looks properly native is in the case of games.
  110. wat? Saturday, 10 August 13 This is because your game

    probably has its own unique style, with custom artwork, and your angry bird (or whatever) has no need at all to look like a standard Android button. If you are developing games, then go out there and use a cross-platform toolkit. It probably makes sense!
  111. Native Saturday, 10 August 13 The final way to develop

    an app is by going fully native.
  112. Apps designed for one platform Saturday, 10 August 13 If

    you care about making an app that works well on a given platform, producing an app with the official framework for the platform is basically the best way to do it.
  113. Saturday, 10 August 13 Writing native code is preferable because

    you get to tie into useful and unique features of the OS for free <CLICK> you get structured navigation that behaves the same as every other app <CLICK> you get access to other apps, such as through the share dialog. These are features that users like, because it makes your app feel like it’s part of a system that they’re already familiar with.
  114. Saturday, 10 August 13 Writing native code is preferable because

    you get to tie into useful and unique features of the OS for free <CLICK> you get structured navigation that behaves the same as every other app <CLICK> you get access to other apps, such as through the share dialog. These are features that users like, because it makes your app feel like it’s part of a system that they’re already familiar with.
  115. Saturday, 10 August 13 Writing native code is preferable because

    you get to tie into useful and unique features of the OS for free <CLICK> you get structured navigation that behaves the same as every other app <CLICK> you get access to other apps, such as through the share dialog. These are features that users like, because it makes your app feel like it’s part of a system that they’re already familiar with.
  116. PROBLEM Saturday, 10 August 13 The problem is that both

    Android and iOS have chosen obscure platforms to base their SDKs on...
  117. iOS: Obj-C Android: “Java” Saturday, 10 August 13 iOS uses

    Objective-C, which had been the language for Mac development before it. Android uses Java, but not the standard, well-known Java that interoperates with a lot of things, but instead they have their own VM implementation. That’s a problem.
  118. No native APIs for other languages. Saturday, 10 August 13

    There’s effectively no native API on either platform for languages other than the “official” one. Indeed, Apple banned the use of languages other than Objective-C for quite some time, back when they were trying to get Flash apps off the device. Android will let you run any language that compiles to Java or JVM byte code, but nothing else can get at the full Android API.
  119. Self-selecting developer communities Saturday, 10 August 13 This means that

    the communities that came to Android and iOS were self-selected. Mac developers had a skill that let them come to iOS. Java developers came to Android because they already knew how to code Java. More concerning: as the platforms grew, people who want to code Android apps have come to learn Java -- because that’s the only way that they can produce a native app. People who want to develop for their mobile devices do so in the native language, because that’s what there.
  120. Function trumps language Saturday, 10 August 13 And so while

    we know that Python is a great language for developing in, users are going to prefer an Android app written in Java: not because of the language that it’s written in, but because it’s native, and it fits in with the rest of the system they use.
  121. Apps • Mobile web • Cross-platform • Native • Why

    users care • Why developers don’t use Python Saturday, 10 August 13 So, to recap: there are three ways of developing mobile apps: There’s the Mobile web, which is about as solved as it will ever be for Python, but requires extra care to produce something that is reliable and that people will want to use. Cross-platform toolkits are good, but they don’t give you a native UI. Native apps are the best because they fit in with the system in general, but you’re stuck using the official language to do dev in.
  122. 3. Python Saturday, 10 August 13 So, we know what

    Android is; we know what Mobile apps are... The last question here is where Python fits into all of this. What’s out there already? What can we do to improve things?
  123. Very little code 30,000ft view Saturday, 10 August 13 This

    is not going to cover a lot of code, but I’m going to show you what’s out there.
  124. python-for-android http://python-for-android.readthedocs.org Saturday, 10 August 13 First up is a

    project called python-for-android. This is a project that’s working on making Python apps deployable on Android.
  125. python-for-android • APK packaging • Tools for dependency management •

    Basic API for bootstrapping an app • No complete UI API. Saturday, 10 August 13 Python-for-android’s main selling point is that it bundles up Android packages for you, containing a Python interpreter, your code, and all of the dependency libraries. It contains a small API that bootstraps your Android app, so that you can actually run it. What it doesn’t provide is anything resembling a UI API. You’ll need to find one of those yourself. Python-for-android means that at least it’s possible to get your Python code running on your Android device, as an app.
  126. Semi-Native http://kivy.org Saturday, 10 August 13 Probably the best Python

    toolkit for mobile apps that’s out there is Kivy. It’s a touch-centric UI library, written for Python. It supports Android, iOS, Linux, Windows and Mac. It’s MIT-licensed open source. The Kivy project is also responsible for the Python-on-android project, so they’re doing most of the heavy lifting for getting other libraries onto Android as well.
  127. Saturday, 10 August 13 Kivy consists of a Yaml-like design

    language for drawing up your UI, and most of the widgets in it are custom -- so you won’t get something that resembles a native Android UI.
  128. http://fresklabs.com/projects/bargenius Saturday, 10 August 13 But, if your app has

    a unique styling, and can’t benefit from a traditional navigation structure, this might not be such a problem. Here’s an example from Kivy’s app gallery -- it’s a restaurant menu app written in Kivy. The styling is completely custom.
  129. Saturday, 10 August 13 Likewise, it’s good for games --

    there’s only one standard UI control on there, and that’s the button in the lower right corner.
  130. Kivy • Designed for Python • Community Support • Cross-platform

    (iOS, Android, Mac, Windows) Saturday, 10 August 13 Kivy’s probably the only mobile toolkit designed with Python in mind, and it’s definitely worth you looking at it. It’s core development is paid through crowd-funding and bounties, but it’s primarily community developed. There’s no commercial support for the library either.
  131. Semi-Native http://qt-project.org/wiki/PySide_for_Android_guide Saturday, 10 August 13 Qt’s another venerable option

    for making semi-native apps. Qt’s been around for ages, and back while it was owned by Nokia, there was a lot of work done on making it work in a touch environment. Qt 5.1 has a tech demo for Android, and Qt4 runs Android already. And there are Python bindings available for Qt as well -- so using Python-for-android means you can use your use Python bindings on Android.
  132. Native Saturday, 10 August 13 So, what then, about making

    Native apps in Python?
  133. Saturday, 10 August 13 Well, the answer to that is,

    you don’t really have any choice other than to use Java. You can also use any number of languages that compile to Java code, or to JVM bytecode -- as long as they’re compiled on the development environment.
  134. Jython? Saturday, 10 August 13 So this gives me a

    chance to answer a question that I always get asked: We’re using Java -- Can’t we just use Jython?
  135. Jython: No. Saturday, 10 August 13 And the answer to

    that is No. Here’s why:
  136. Write in Java Compile to JVM Bytecode Execute on Dalvik

    VM Covert to Dalvik Bytecode Saturday, 10 August 13 So if you remember back earlier, to write a Java app for Android, you need convert your JVM bytecode <CLICK> to Dalvik bytecode on the development environment.
  137. Write in Java Compile to JVM Bytecode Execute on Dalvik

    VM Covert to Dalvik Bytecode dev env target Saturday, 10 August 13 So if you remember back earlier, to write a Java app for Android, you need convert your JVM bytecode <CLICK> to Dalvik bytecode on the development environment.
  138. Write in Python Execute in Jython interpreter Execute on JVM

    Saturday, 10 August 13 Well, with Jython, the process resembles Python considerably more. Except that if you try to import a library, JVM bytecode is generated, and that is execeuted. And all of this bytecode generation happens on the target device. So, the Jython interpreter will probably run, but you can’t get it to produce code that will run on the target platform. That’s annoying.
  139. Write in Python Execute in Jython interpreter Execute on JVM

    Generate JVM byte code Saturday, 10 August 13 Well, with Jython, the process resembles Python considerably more. Except that if you try to import a library, JVM bytecode is generated, and that is execeuted. And all of this bytecode generation happens on the target device. So, the Jython interpreter will probably run, but you can’t get it to produce code that will run on the target platform. That’s annoying.
  140. Write in Python Execute in Jython interpreter Execute on JVM

    Generate JVM byte code dev env target Saturday, 10 August 13 Well, with Jython, the process resembles Python considerably more. Except that if you try to import a library, JVM bytecode is generated, and that is execeuted. And all of this bytecode generation happens on the target device. So, the Jython interpreter will probably run, but you can’t get it to produce code that will run on the target platform. That’s annoying.
  141. Abandonware? Saturday, 10 August 13 Jython is also probably the

    least actively maintained Python interpreter that’s available.
  142. Saturday, 10 August 13 There’ve been a few attempts at

    making a fork of Jython to support android, but they’ve all been abandoned, and subsequently re-forked. <CLICK> and the last attempt at making this work was made more than two years ago. Not a terribly good sign.
  143. Saturday, 10 August 13 There’ve been a few attempts at

    making a fork of Jython to support android, but they’ve all been abandoned, and subsequently re-forked. <CLICK> and the last attempt at making this work was made more than two years ago. Not a terribly good sign.
  144. Jython • 2.7... beta • 2.5 stable • 3.x? No

    sign of it Saturday, 10 August 13 The most recent release of Jython is a beta of 2.7 -- three years after CPython supported it. There’s no sign of a 3.x support. While Jython lags so far behind CPython, it’s really not worth supporting on Android.
  145. Cpython Saturday, 10 August 13 So that leaves the matter

    of CPython. Python-on-android shows that we can get CPython running on Android devices, and running like normal apps at that. So can we use CPython to get at the Java API for Android?
  146. Python CPython VM Python-C Extensions Anything at all that has

    a C API Saturday, 10 August 13 Well, Python has a C API, which can be used either to call out to C libraries, or to embed a Python interpreter inside a C-based binary on your machine. And being able to call out to C libraries basically exposes Python to every piece of software on your machine.
  147. Python CPython VM Python-C Extensions Anything at all that has

    a C API ALL OF THE THINGS ON YOUR COMPUTER, EVER Saturday, 10 August 13 Well, Python has a C API, which can be used either to call out to C libraries, or to embed a Python interpreter inside a C-based binary on your machine. And being able to call out to C libraries basically exposes Python to every piece of software on your machine.
  148. Java Java VM Java Native Interface Anything at all that

    has a C API Saturday, 10 August 13 Meanwhile, Java has pretty much exactly the same thing -- the Java Native Interface lets you call back into C code from Java -- or to call Java code from within C <CLICK> And happily, Android implements the JNI in its entirety, so Android apps can also call out to C libraries...
  149. Java Java VM Java Native Interface Anything at all that

    has a C API Dalvik VM Saturday, 10 August 13 Meanwhile, Java has pretty much exactly the same thing -- the Java Native Interface lets you call back into C code from Java -- or to call Java code from within C <CLICK> And happily, Android implements the JNI in its entirety, so Android apps can also call out to C libraries...
  150. Java Java VM Java Native Interface Python CPython VM Python-C

    Extensions Saturday, 10 August 13 So, if Python has a way of being embedded inside a C library... and Java has a way of calling out to C library. Then all we need is some <CLICK> magic piece of code that will let us bridge the two interfaces.
  151. Java Java VM Java Native Interface Python CPython VM Python-C

    Extensions MAGIC! Saturday, 10 August 13 So, if Python has a way of being embedded inside a C library... and Java has a way of calling out to C library. Then all we need is some <CLICK> magic piece of code that will let us bridge the two interfaces.
  152. Kivy (again) Saturday, 10 August 13 And thanks, once again

    to the Kivy project!
  153. Pyjnius Saturday, 10 August 13 They’ve produced a library called

    Pyjnius -- it’s a bridge that lets you use the JNI from within CPython. This means that you call into JNI methods from within your Python code.
  154. System = autoclass('java.lang.System') System.out.println('Hello World') Saturday, 10 August 13 So,

    here’s Hello World in Pyjnius -- see that “autoclass” thing? That’s Pyjnius using the JNI to introspect the Java.lang.System class, and producing a Python API for it. Then, we can simply call into System.out.println Java method from within Python.
  155. from jnius import autoclass Stack = autoclass('java.util.Stack') stack = Stack()

    stack.push('hello') stack.push('world') print stack.pop() # --> 'world' print stack.pop() # --> 'hello' Saturday, 10 August 13 And even better, it translates between Python and Java types for you -- so this code puts Python strings into a Java Stack, and vice-versa.
  156. from jnius import PythonJavaClass, java_method class OnClickListener(PythonJavaClass): __javainterfaces__ = ['android.view.OnClickListener']

    def __init__(self): pass @java_method('()Z') def onClick(self): pass Saturday, 10 August 13 And also importantly, you can provide implementations of Java interfaces for use with the Android API. This means you can do things like listen for Android UI events. All you need to do is derive from PythonJavaClass; declare which Java interfaces you implement, and then provide the java_method decorator on every method that implements an interface method.
  157. What’s Missing? Saturday, 10 August 13 So, this is a

    very good start. It lets you use a very large proportion of the Android API, but it doesn’t get you the whole way there.
  158. Pyjnius Problems • Can’t override Java classes (only interfaces) •

    Have to write a lot of code in Java still • Implementing methods is very rough • Android API very Java-like Saturday, 10 August 13 First up, you can’t override a Java class. You can only implement interfaces. In any case where you need to override a class, you’ll still need to write Java code at the moment. Also, where you implement Java interfaces, you still need to provide raw JNI signatures, which are ugly strings describing the arguments and return type. Finally, the API is very idiomatic Java. Even with a working API, the framework will feel verbose.
  159. Where to from here? Saturday, 10 August 13 So, given

    that there are some problems, what can we do to fix them? Well the most important thing preventing us from making a working native app in Android is not being able to access the entirety of the SDK.
  160. Write Python Code Generate some Java Done! Saturday, 10 August

    13 The obvious solution is adding a build phase when you produce your Android package. All the code that currently needs to be written in Java could be written in Python with bridging Java code generated at build/packaging time. Come speak to me after the talk for ideas on how you’d do this.
  161. Summary • Games: Kivy or PyGame • Cross-platform UI: Kivy

    or Qt+PySide • Pyjnius: Best hope for native Saturday, 10 August 13 So, that’s the state of app development in Python on Android. Kivy is probably the most complete option out there for producing apps that run on Android, and they’re doing the work in making Python run on Android in general. Kivy’s PyJNIus project is probably our best shot at getting native UIs happening on Android.
  162. Epilogue Saturday, 10 August 13 So, that brings us to

    the end of this talk. As Python programmers we’d very much like to be able to make great Android apps in Python.
  163. Things aren’t good Saturday, 10 August 13 Unfortunatelty, we’re not

    at the point where we can do that. There are cross-platform libraries that get us part of the way there...
  164. Things aren’t good (yet). Saturday, 10 August 13 ... but

    there’s good work that’s getting Python ready to be a first-class language on Android. It’s important work. Because it means that people who decide they want to learn to code because they want to make apps on their phone can choose Python as a language.
  165. Y PYTHON? Saturday, 10 August 13 So, let’s return to

    that question I asked when I opened the talk: Why do people use Python?
  166. • Easy to learn • Easy to read • Easy

    to maintain • Community • spam • Standard library • spam • External packages for all of the things • Open source • eggs • Documentation • spam Saturday, 10 August 13 Well, there is the whole heap of things that you all said on Twitter. <CLICK> but I don’t think that’s the answer.
  167. • Easy to learn • Easy to read • Easy

    to maintain • Community • spam • Standard library • spam • External packages for all of the things • Open source • eggs • Documentation • spam Saturday, 10 August 13 Well, there is the whole heap of things that you all said on Twitter. <CLICK> but I don’t think that’s the answer.
  168. People use Python because Saturday, 10 August 13 The actual

    answer is much simpler. People use python because...
  169. People use Python because it solves their problems Saturday, 10

    August 13 ... because Python solves development problems that people actually have.
  170. Web dev Saturday, 10 August 13 People use Python for

    web development -- some of us have been using Python for Web development for a very long time...
  171. Web dev Saturday, 10 August 13 ... but most of

    us didn’t use Python for web dev until after Django came along. Because Django made web programming in Python easy.
  172. API clients Saturday, 10 August 13 I’ve used Python to

    talk to Web APIs for years...
  173. API clients Requests Saturday, 10 August 13 ... but it

    wasn’t a task I’d enjoy until Requests came along.
  174. Python has great libraries That solve problems people actually have.

    Saturday, 10 August 13 So when we talk about Python being a great language, we mean that Python is great at solving problems that we already have... And these libraries exist because Python developers have seen a problem with what’s already out there, and fixed it. These developers have stood on the shoulders of giants.
  175. Android dev? Saturday, 10 August 13 So, where does that

    leave Android?
  176. Android dev? ??? Saturday, 10 August 13 Well, for Python,

    it’s not really a first class option.
  177. Android dev? Java (eew) Saturday, 10 August 13 So that

    means for the time being, we need to code in Java...
  178. Android dev? Java (eew) Saturday, 10 August 13 ... eew.

    But before you hate on Java, remember that Android devs are using Java for the same reason we like to use Python.
  179. People use Java on Android because it lets them solve

    their problems Saturday, 10 August 13 Java on Android solves problems that people have while...
  180. Python on Android Saturday, 10 August 13 Python on Android...

    (NEXT SLIDE) does not
  181. Python on Android does not. Saturday, 10 August 13 (NEXT

    SLIDE)
  182. Python on Android does not (yet). Saturday, 10 August 13

  183. • Easy to learn • Easy to read • Easy

    to maintain • Community • spam • Standard library • spam • External packages for all of the things • Open source • eggs • Documentation • spam Saturday, 10 August 13 But we know that Python’s a great language, and developers on all platforms deserve to be able to use it.
  184. Python can be a great language for Android Saturday, 10

    August 13 Python’s in a great position to be a better language for Android development than Java could ever be. We have a huge advantage in being simple, elegant, and quick to code... but before we can be a great language for Android development...
  185. Python can be a great language for Android Saturday, 10

    August 13 we need to be a language where Android development is viable.
  186. <PICTURE REQUIRED> Saturday, 10 August 13 To be able to

    stand on the shoulders of giants requires there to be giants in the first place. So, go hack on JNIus -- make it easy for Python people to pick up -- make it look like Python and not the JNI. Once it’s great for Python people to use, Android can be ripe for Android people to improve.
  187. - End - Christopher Neugebauer chris.neugebauer.id.au chrisjrn@gmail.com @chrisjrn Saturday, 10

    August 13 Thank you.