92
Building Apps for Multiple Devices Terry Ryan Developer Evangelist http://terrenceryan.com @tpryan

Building apps for multiple devices

Embed Size (px)

DESCRIPTION

A session on using Flex and AIR to develop application that can run on IOS, Android,or PlayBook. A primer on getting at least close to the dream of one code base, multiple devices.

Citation preview

Page 1: Building apps for multiple devices

Building Apps for Multiple Devices

Terry RyanDeveloper Evangelisthttp://terrenceryan.com@tpryan

Page 2: Building apps for multiple devices

Let me start a process here

Page 3: Building apps for multiple devices

Poll

• How many have done native mobile?• How many have done mobile

AIR?• How many have done mobile

AIR with Flex?• How many have done it for

multiple platforms?

Page 4: Building apps for multiple devices

You can do cross platform mobile

development with Adobe AIR!!!

Page 5: Building apps for multiple devices

Wooooooh!!!!!!

Page 6: Building apps for multiple devices

We a wrote very good demo project.

Actual mileage may vary.

Page 7: Building apps for multiple devices

Noooooo!!!!!!

Page 8: Building apps for multiple devices

Please, I beg you, button, stop appearing off-screen

Page 9: Building apps for multiple devices

My goal: give you guys an idea of what you

need to do to actually produce multi-screen

apps

Page 10: Building apps for multiple devices

Using one code base

Page 11: Building apps for multiple devices

Should you do this?

Page 12: Building apps for multiple devices

Content

• Design• Develop• Publish

• Flex with a little ActionScript only

Page 13: Building apps for multiple devices

Designing for Multiple Devices

Page 14: Building apps for multiple devices

Resolution and DPI

Page 15: Building apps for multiple devices
Page 16: Building apps for multiple devices
Page 17: Building apps for multiple devices
Page 18: Building apps for multiple devices
Page 19: Building apps for multiple devices

DPI FUBAR

Page 20: Building apps for multiple devices

So how do we deal with this?

Page 21: Building apps for multiple devices

Application DPI

• This is the DPI of the device you are targeting in development• Allows for resizing to

denser devices

Page 22: Building apps for multiple devices

Application DPI

• 3 Levels–160–240–320

Page 23: Building apps for multiple devices

Media Queries

• CSS media queries allow you to target different DPI screens naturally

Page 24: Building apps for multiple devices

Media Queries

@media all and (application-dpi: 160){

s|Button{

color: red;}

}

@media all and (application-dpi: 240){

s|Button{

color: green;}

}

Page 25: Building apps for multiple devices

Media Query Options

• ApplicationDPI• OS

Page 26: Building apps for multiple devices

Personal Thought on OS Media Queries

• Don’t do it if you want to keep a unified code base• Handle Density and screen

size, but not OS

Page 27: Building apps for multiple devices

Demo

Application DPI and Media Queries in Flex

Page 28: Building apps for multiple devices

Deeper Dive

Narciso JaramilloDeep Dive Into Multi Density & Multi Platform Application

Development

Page 29: Building apps for multiple devices

ActionScript Only

• Roll your own looking at:–stage.fullScreenWidth• In development I’ve had issues with stage.stageWidth

–Capabilities.screenDPI

Page 30: Building apps for multiple devices

Demo

Application Sizing in ActionScript

Page 31: Building apps for multiple devices

Flash Builder Simulating

• Flex–In Design View–At compile

• ActionScript–At compile

Page 32: Building apps for multiple devices

!=

Page 33: Building apps for multiple devices
Page 34: Building apps for multiple devices
Page 35: Building apps for multiple devices

Developing for Multiple Devices

Page 36: Building apps for multiple devices

Don’t tweak for devices in code.

Page 37: Building apps for multiple devices

If you can avoid it.

Page 38: Building apps for multiple devices

But what about diff erences between UI

controls IOS vs Android vs

PlayBook

Page 39: Building apps for multiple devices

It depends

Page 40: Building apps for multiple devices

Configuring for Multiple Devices

Page 41: Building apps for multiple devices

Application Descriptor

• You know that XML file• Special settings for–Android –IOS

Page 42: Building apps for multiple devices

BlackBerry Descriptor

BlackBerry Uses Application Descriptor and another file:

blackberry-tablet.xml

Page 43: Building apps for multiple devices

BlackBerry Descriptor

• Allows you to make transparent apps and change preview icons.• Transparent apps aren’t

supported on other platforms

Page 44: Building apps for multiple devices

Android Settings

• Permissions• Custom URI• Compatibility Filtering• Install Location

Page 45: Building apps for multiple devices

Android Permissions

• ACCESS_COARSE_LOCATION• ACCESS_FINE_LOCATION• ACCESS_NETWORK_STATE • ACCESS_WIFI_STATE • CAMERA • INTERNET • READ_PHONE_STATE• RECORD_AUDIO• WAKE_LOCK • WRITE_EXTERNAL_STORAGE

Page 46: Building apps for multiple devices

Android Custom URI

• Allow web pages or other android apps to launch your app from a url when the application is installed.

Page 47: Building apps for multiple devices

Android Custom URI

<activity> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.BROWSABLE"/> <category android:name="android.intent.category.DEFAULT"/> <data android:scheme="myURI"/> </intent-filter> </activity>

URL would be:myURI://com.myApp.uniquename

Where com.myApp.uniquename is the app id from your descriptor

Page 48: Building apps for multiple devices

Android compatibility fi ltering

• Permissions assume all or nothing• So if a feature is optional,

you have to set it such or it won’t show up in store• Important for Camera,

Audio

Page 49: Building apps for multiple devices

Camera Filtering

<uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera" android:required="false"/> <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/> <uses-feature android:name="android.hardware.camera.flash" android:required="false"/>

Page 50: Building apps for multiple devices

Android Instal Location

<android> <manifestAdditions> <![CDATA[ <manifest android:installLocation="preferExternal"/> ]]> </manifestAdditions> </android>

Page 51: Building apps for multiple devices

IOS Settings

• Models• Resolution• Custom URI• Compatibility Filtering• Exit or Pause

Page 52: Building apps for multiple devices

Models

<key>UIDeviceFamily</key> <array> <string>1</string> <!-- iPod/iPhone --> <string>2</string> <!-- iPad --></array>

Page 53: Building apps for multiple devices

Resolution

<requestedDisplayResolution>high</requestedDisplayResolution>

High wil l al low you to draw single pixels on a high resolution screen, otherwise 1 pixel = 4 pixels

Page 54: Building apps for multiple devices

Custom URI

<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>myURI</string> </array> <key>CFBundleURLName</key> <string>com.myApp.uniquename</string> </dict> </array>

URL would be:myURI://com.myApp.uniquename

I f you set this to be the same as your application id you get compatibil ity with Android apps.

Page 55: Building apps for multiple devices

IOS compatibility fi ltering

Like Android it’s about discoverability and installation, not usage.

Page 56: Building apps for multiple devices

Compatibility Filtering

<key>UIRequiredDeviceCapabilities</key> <array> <string>microphone</string> <string>still-camera</string> </array>

Page 57: Building apps for multiple devices

Exit or Pause

<key>UIApplicationExitsOnSuspend</key> <string>YES</string>

Page 58: Building apps for multiple devices

Icon sizes

Icon Size Platform

16 Desktop

29 IOS

32 Desktop

36 Android

48 Android, IOS, Desktop

57 IOS

72 Android,IOS

86 PlayBook

114 IOS

128 Desktop

512 IOS

Page 59: Building apps for multiple devices

AIR Versions

• There are some issues with AIR version and target–BlackBerry - 2.5–Android - 2.6–IOS -2.6, or 2.0 or 2.7

Page 60: Building apps for multiple devices

But that’s hard set

<application xmlns="http://ns.adobe.com/air/application/2.6">

Page 61: Building apps for multiple devices

Multiple Descriptors

• Solution:

Page 62: Building apps for multiple devices

Publishing for Multiple Devices

Page 63: Building apps for multiple devices

Flash Builder

• Publish to all platforms at the same time

Page 64: Building apps for multiple devices

Compiling and Packaging

• Flash Builder uses features that are accessible through command line tools • Often using those tools• Therefore before it can be a

feature in Flash Builder, has to be available in command line

Page 65: Building apps for multiple devices

Flash Builder vs Command line

• Flash Builder will often lack ui that the command line exposes• So it behooves you to learn

command line

Page 66: Building apps for multiple devices

Case in point

• Publishing AIR files compatible with Amazon Store

Page 67: Building apps for multiple devices

Command line Compiling

• OS Scripts• ANT (what I use)• Maven

Page 68: Building apps for multiple devices

Tools

• ANT• MXMLC• AIR Packagers–ADT–blackberry-airpackager–pfi (no longer needed)

Page 69: Building apps for multiple devices

Process

• Compile SWF• Gather External Resources• Package for target device

Page 70: Building apps for multiple devices

Compiling

• Requires MXMLC• In ANT requires MXMLC

Task• Despite the name, works

for non MXML apps. • Doesn’t add the Flex

Framework or anything either.

Page 71: Building apps for multiple devices

Compiling via ANT

<mxmlc file="${projectFile}" output="${device.swf}" > <load-config filename="${FLEX_HOME}/frameworks/airmobile-

config.xml"/> <source-path path-element= "${FLEX_HOME}/frameworks" /><static-link-runtime-shared-libraries />

<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true"> <include name="libs/*" />

</compiler.library-path></mxmlc>

Page 72: Building apps for multiple devices

Compiling via ANT

<load-config filename="${FLEX_HOME}/frameworks/airmobile-config.xml"/>

On Desktops

<load-config filename="${FLEX_HOME}/frameworks/air-config.xml"/>

Page 73: Building apps for multiple devices

Demo

Command Line Compiling with ANT

Page 74: Building apps for multiple devices

Gathering Files

• SWF• Any assets used in

application• Application descriptor file

Page 75: Building apps for multiple devices

Application Descriptor

Most have a line: <content>[This value will be overwritten by Flash Builder in the output app.xml]</content>

It won’t so you have to.

Page 76: Building apps for multiple devices

Packaging for Android

<exec executable="${ADT}" dir="${android.collect}"><arg value="-package"/><arg line="-target apk"/><arg line="-storetype pkcs12"/><arg line="-keystore ${cert}" /><arg line="-storepass ${cert.password}" /><arg value="${app.name}"/><arg value="${app.name}-app.xml"/><arg value="${app.name}.swf"/><arg value="assets"/>

</exec>

Page 77: Building apps for multiple devices

Packaging for Android

<arg line="-target apk "/>

Options include • apk• apk-debug• apk-emulator

Page 78: Building apps for multiple devices

Packaging for IOS

<exec executable="${ADT}" dir="${ios.collect}"><arg value="-package"/><arg line="-target ipa-ad-hoc "/><arg line="-storetype pkcs12 "/><arg line="-keystore ${ios.cert} " /><arg line="-storepass ${ios.certpass} " /><arg line="-provisioning-profile $

{ios.provision} " /><arg value="${app.name}.ipa"/><arg value="${app.name}-app.xml"/><arg value="${app.name}.swf"/><arg value="assets"/>

</exec>

Page 79: Building apps for multiple devices

Packaging for IOS

<arg line="-target ipa-ad-hoc "/>

Options include • ipa-test• ipa-debug• ipa-app-store• ipa-ad-hoc

Page 80: Building apps for multiple devices

Packaging for BlackBerry

<exec executable="${bb.packager}" dir="${bb.collect}"><arg value="-package"/><arg value="${app.name}.bar"/><arg value="${app.name}-app.bb.xml"/><arg value="${app.name}.swf"/>

</exec>

Page 81: Building apps for multiple devices

Tons of options

Page 82: Building apps for multiple devices

Packaging for BlackBerry

-package - command to package -target (bar|bar-debug) - target format bar or bar-debug -connect <host> - host ip address for debugging -no-validation - turn off air and bar validation -list-files - list all files in the resulting package -env <var>=<value> - set an extra environment variable for the runtime -barVersion <version> - run in compatibility mode (set older version to be compatible with) -publisher - set the publisher (author) name -buildId - set the build id (4th segment of the version) -devMode - package in development mode<signing options> (part of packaging options): -signDev - command to sign with developer's certificate -keystore <store> - keystore file -storepass <pass> - store password for certificate store -signRim - command to sign by rim (requires internet connection) -cskpass <pass> - password to encrypt long-lived keys<deployment_options>: -installApp - command to install the package -launchApp - command to launch the app -device <deviceId> - set host name or IP address of the target -password <password> - device password

Page 83: Building apps for multiple devices

Packaging for BlackBerry

• Debugging• Installation and launching• Signing

Page 84: Building apps for multiple devices

Demo

Command Line Packagingwith ANT

Page 85: Building apps for multiple devices

Packaging for Amazon

<exec executable="${ADT}" dir="${android.collect}"><arg value="-package"/><arg line="-target apk"/><arg line="-airDownloadURL ${amazon.url}"/><arg line="-storetype pkcs12"/><arg line="-keystore ${cert}" /><arg line="-storepass ${cert.password}" /><arg value="${app.name}"/><arg value="${app.name}-app.xml"/><arg value="${app.name}.swf"/><arg value="assets"/>

</exec>

Page 86: Building apps for multiple devices

So should you do this?

Page 87: Building apps for multiple devices

My Weasely answer:It Depends

Page 88: Building apps for multiple devices

Can you wait for the next version of AIR?

Page 89: Building apps for multiple devices

Is your app your competitive advantage,

or a cost center?

Page 90: Building apps for multiple devices

Is your audience spread out on devices?

Page 91: Building apps for multiple devices

Studio Cloud

Page 92: Building apps for multiple devices

Follow up?

• Feel free to contact me–[email protected]–http://terrenceryan.com–Twitter: @tpryan