Slide 1

Slide 1 text

Saturday, 10 August 13

Slide 2

Slide 2 text

Android The Land that Python Forgot? Christopher Neugebauer PyCon Canada 10 August 2013 chris.neugebauer.id.au [email protected] @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!

Slide 3

Slide 3 text

Hello! Saturday, 10 August 13 HI! I’d like to thank PyCon Canada for the opportunity to present...

Slide 4

Slide 4 text

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...

Slide 5

Slide 5 text

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.

Slide 6

Slide 6 text

Saturday, 10 August 13 I asked everyone on twitter to tell me why they use Python.

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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.

Slide 15

Slide 15 text

Mobile (it’s a thing) Saturday, 10 August 13

Slide 16

Slide 16 text

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.

Slide 17

Slide 17 text

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.

Slide 18

Slide 18 text

WHY? Saturday, 10 August 13

Slide 19

Slide 19 text

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.

Slide 20

Slide 20 text

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?

Slide 21

Slide 21 text

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.

Slide 22

Slide 22 text

About me Python native Saturday, 10 August 13 I’m a Python native

Slide 23

Slide 23 text

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.

Slide 24

Slide 24 text

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.

Slide 25

Slide 25 text

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.

Slide 26

Slide 26 text

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. this makes me sad.

Slide 27

Slide 27 text

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. this makes me sad.

Slide 28

Slide 28 text

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?

Slide 29

Slide 29 text

Mobile Saturday, 10 August 13 So let’s start by looking at what Mobile computing is...

Slide 30

Slide 30 text

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.

Slide 31

Slide 31 text

• 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 -- snake. It was a simple game that I could pick up randomly on the bus

Slide 32

Slide 32 text

• 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 -- snake. It was a simple game that I could pick up randomly on the bus

Slide 33

Slide 33 text

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.

Slide 34

Slide 34 text

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.

Slide 35

Slide 35 text

• 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.

Slide 36

Slide 36 text

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?

Slide 37

Slide 37 text

It’s an operating system Saturday, 10 August 13 At its simplest, Android is an Operating System...

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

It’s an operating system for tablets Saturday, 10 August 13 Tablet devices...

Slide 40

Slide 40 text

It’s an operating system for your sunglasses Saturday, 10 August 13 ... with Google Glass, it even runs on Sunglasses.

Slide 41

Slide 41 text

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...

Slide 42

Slide 42 text

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.

Slide 43

Slide 43 text

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.

Slide 44

Slide 44 text

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...

Slide 45

Slide 45 text

(low concentration threshold) Saturday, 10 August 13 ... Lest a traffic accident happen.

Slide 46

Slide 46 text

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)

Slide 47

Slide 47 text

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.

Slide 48

Slide 48 text

Saturday, 10 August 13 Visual design is usually treated as part of the development process than you may otherwise be familiar with. 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.

Slide 49

Slide 49 text

Saturday, 10 August 13 Visual design is usually treated as part of the development process than you may otherwise be familiar with. 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.

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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*

Slide 52

Slide 52 text

Curated software distribution Saturday, 10 August 13 Possibly the most important hallmark of modern Mobile devices is having curated software distribution.

Slide 53

Slide 53 text

Emphasis on native Saturday, 10 August 13 The emphasis of software curation is to produce software that natively targets a given system.

Slide 54

Slide 54 text

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.

Slide 55

Slide 55 text

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. Let’s take a look at them.

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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.

Slide 61

Slide 61 text

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.

Slide 62

Slide 62 text

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.

Slide 63

Slide 63 text

Saturday, 10 August 13 Users can store themselves in faraday cages;

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

Saturday, 10 August 13 Or they could just voluntarily lock themselves into an unreliable network.

Slide 66

Slide 66 text

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.

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

Low-Effort UI + Native Ecosystem + Network Resilience = Android UX Saturday, 10 August 13 These things *in concert* are what we refer to as UX.

Slide 69

Slide 69 text

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...

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

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

Slide 72

Slide 72 text

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. 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”.

Slide 73

Slide 73 text

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. 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”.

Slide 74

Slide 74 text

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 cannot typically happen on the target.

Slide 75

Slide 75 text

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 cannot typically happen on the target.

Slide 76

Slide 76 text

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.

Slide 77

Slide 77 text

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?

Slide 78

Slide 78 text

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. Important: the conversion phase MUST happen on the device you’re developing on. It doesn’t happen on the device.

Slide 79

Slide 79 text

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. Important: the conversion phase MUST happen on the device you’re developing on. It doesn’t happen on the device.

Slide 80

Slide 80 text

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

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

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.

Slide 83

Slide 83 text

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

Slide 84

Slide 84 text

Three Types Saturday, 10 August 13 There are basically three ways you can go about making an app that runs on Android:

Slide 85

Slide 85 text

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.

Slide 86

Slide 86 text

Mobile Web Saturday, 10 August 13 So, the least native way to target a mobile device is to produce a mobile web app.

Slide 87

Slide 87 text

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.

Slide 88

Slide 88 text

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.

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

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. 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:

Slide 91

Slide 91 text

“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. 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:

Slide 92

Slide 92 text

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. So let’s take a look at a couple of reasons why web apps might not be

Slide 93

Slide 93 text

“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. So let’s take a look at a couple of reasons why web apps might not be

Slide 94

Slide 94 text

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.

Slide 95

Slide 95 text

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.

Slide 96

Slide 96 text

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.

Slide 97

Slide 97 text

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.

Slide 98

Slide 98 text

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.

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

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)

Slide 101

Slide 101 text

Python for Mobile Web? Saturday, 10 August 13 So you might be wondering that the status is with Python and mobile web.

Slide 102

Slide 102 text

Solved Saturday, 10 August 13 It’s basically a solved problem...

Slide 103

Slide 103 text

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.

Slide 104

Slide 104 text

Semi-Native Saturday, 10 August 13 The second kind of app I want to look at are “semi-native” apps...

Slide 105

Slide 105 text

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.

Slide 106

Slide 106 text

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)

Slide 107

Slide 107 text

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.

Slide 108

Slide 108 text

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.

Slide 109

Slide 109 text

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.

Slide 110

Slide 110 text

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!

Slide 111

Slide 111 text

Native Saturday, 10 August 13 The final way to develop an app is by going fully native.

Slide 112

Slide 112 text

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.

Slide 113

Slide 113 text

Saturday, 10 August 13 Writing native code is preferable because you get to tie into useful and unique features of the OS for free you get structured navigation that behaves the same as every other app 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.

Slide 114

Slide 114 text

Saturday, 10 August 13 Writing native code is preferable because you get to tie into useful and unique features of the OS for free you get structured navigation that behaves the same as every other app 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.

Slide 115

Slide 115 text

Saturday, 10 August 13 Writing native code is preferable because you get to tie into useful and unique features of the OS for free you get structured navigation that behaves the same as every other app 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.

Slide 116

Slide 116 text

PROBLEM Saturday, 10 August 13 The problem is that both Android and iOS have chosen obscure platforms to base their SDKs on...

Slide 117

Slide 117 text

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.

Slide 118

Slide 118 text

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.

Slide 119

Slide 119 text

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.

Slide 120

Slide 120 text

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.

Slide 121

Slide 121 text

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.

Slide 122

Slide 122 text

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?

Slide 123

Slide 123 text

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.

Slide 124

Slide 124 text

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.

Slide 125

Slide 125 text

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.

Slide 126

Slide 126 text

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.

Slide 127

Slide 127 text

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.

Slide 128

Slide 128 text

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.

Slide 129

Slide 129 text

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.

Slide 130

Slide 130 text

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.

Slide 131

Slide 131 text

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.

Slide 132

Slide 132 text

Native Saturday, 10 August 13 So, what then, about making Native apps in Python?

Slide 133

Slide 133 text

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.

Slide 134

Slide 134 text

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?

Slide 135

Slide 135 text

Jython: No. Saturday, 10 August 13 And the answer to that is No. Here’s why:

Slide 136

Slide 136 text

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 to Dalvik bytecode on the development environment.

Slide 137

Slide 137 text

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 to Dalvik bytecode on the development environment.

Slide 138

Slide 138 text

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.

Slide 139

Slide 139 text

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.

Slide 140

Slide 140 text

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.

Slide 141

Slide 141 text

Abandonware? Saturday, 10 August 13 Jython is also probably the least actively maintained Python interpreter that’s available.

Slide 142

Slide 142 text

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. and the last attempt at making this work was made more than two years ago. Not a terribly good sign.

Slide 143

Slide 143 text

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. and the last attempt at making this work was made more than two years ago. Not a terribly good sign.

Slide 144

Slide 144 text

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.

Slide 145

Slide 145 text

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?

Slide 146

Slide 146 text

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.

Slide 147

Slide 147 text

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.

Slide 148

Slide 148 text

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 And happily, Android implements the JNI in its entirety, so Android apps can also call out to C libraries...

Slide 149

Slide 149 text

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 And happily, Android implements the JNI in its entirety, so Android apps can also call out to C libraries...

Slide 150

Slide 150 text

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 magic piece of code that will let us bridge the two interfaces.

Slide 151

Slide 151 text

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 magic piece of code that will let us bridge the two interfaces.

Slide 152

Slide 152 text

Kivy (again) Saturday, 10 August 13 And thanks, once again to the Kivy project!

Slide 153

Slide 153 text

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.

Slide 154

Slide 154 text

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.

Slide 155

Slide 155 text

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.

Slide 156

Slide 156 text

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.

Slide 157

Slide 157 text

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.

Slide 158

Slide 158 text

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.

Slide 159

Slide 159 text

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.

Slide 160

Slide 160 text

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.

Slide 161

Slide 161 text

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.

Slide 162

Slide 162 text

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.

Slide 163

Slide 163 text

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...

Slide 164

Slide 164 text

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.

Slide 165

Slide 165 text

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?

Slide 166

Slide 166 text

• 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. but I don’t think that’s the answer.

Slide 167

Slide 167 text

• 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. but I don’t think that’s the answer.

Slide 168

Slide 168 text

People use Python because Saturday, 10 August 13 The actual answer is much simpler. People use python because...

Slide 169

Slide 169 text

People use Python because it solves their problems Saturday, 10 August 13 ... because Python solves development problems that people actually have.

Slide 170

Slide 170 text

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...

Slide 171

Slide 171 text

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.

Slide 172

Slide 172 text

API clients Saturday, 10 August 13 I’ve used Python to talk to Web APIs for years...

Slide 173

Slide 173 text

API clients Requests Saturday, 10 August 13 ... but it wasn’t a task I’d enjoy until Requests came along.

Slide 174

Slide 174 text

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.

Slide 175

Slide 175 text

Android dev? Saturday, 10 August 13 So, where does that leave Android?

Slide 176

Slide 176 text

Android dev? ??? Saturday, 10 August 13 Well, for Python, it’s not really a first class option.

Slide 177

Slide 177 text

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

Slide 178

Slide 178 text

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.

Slide 179

Slide 179 text

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...

Slide 180

Slide 180 text

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

Slide 181

Slide 181 text

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

Slide 182

Slide 182 text

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

Slide 183

Slide 183 text

• 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.

Slide 184

Slide 184 text

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...

Slide 185

Slide 185 text

Python can be a great language for Android Saturday, 10 August 13 we need to be a language where Android development is viable.

Slide 186

Slide 186 text

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.

Slide 187

Slide 187 text

- End - Christopher Neugebauer chris.neugebauer.id.au [email protected] @chrisjrn Saturday, 10 August 13 Thank you.