73
Targeting Android with Qt Espen Riskedal / cutehacks.com @snowpong

Targeting Android with Qt

Embed Size (px)

DESCRIPTION

Explains how to install Necessitas (Qt for Android), how to use it, and how to publish to the Android Market. Based on Necessitas 0.3 (3rd alpha) Slides are from Qt Developer Days 2011 in San Fransisco

Citation preview

Page 1: Targeting Android with Qt

Targeting Android with Qt

Espen Riskedal / cutehacks.com@snowpong

Page 2: Targeting Android with Qt

Introduction

About me,and about the talk.

Page 3: Targeting Android with Qt

About me

● Trolltech and Nokia

● Symbian and Windows CE

● Co-founded cutehacks.com

● Still believe in Qt Everywhere

Espen Riskedal@snowpong

Page 4: Targeting Android with Qt

We make apps

Page 5: Targeting Android with Qt

Purpose of this talk

“Teach you how to publish Qt apps in the Android market”

I have a vested interest.

Page 6: Targeting Android with Qt

Agenda

● Introduction

● Qt on mobile platforms

● Necessitas

● Publishing to Android Market

● Conclusion

Page 7: Targeting Android with Qt

2.3.x “Gingerbread”● Google Nexus S● December 2010● Linux kernel 2.6.35

Photo: flickr.com/quinnanya/CC / Some rights reserved

Page 8: Targeting Android with Qt

Qt on mobile platforms

A brief introduction on which mobile platforms you can target with Qt.

Page 9: Targeting Android with Qt

Today's mobile platforms

Page 10: Targeting Android with Qt

Supported by Qt

Page 11: Targeting Android with Qt

Almost supported by Qt

Page 12: Targeting Android with Qt

Some Android details

● 4 major releases

● ARM and x86

● Linux

● Dalvik

Page 13: Targeting Android with Qt

Well known models

Galaxy S2 Tab 10.1 Xperia Play

Page 14: Targeting Android with Qt

Android API levels

Platform version API Level VERSION_CODE

... ... ...

Android 2.3 – 2.3.2 9 GINGERBREAD

... ... ...

Android 2.1.x 7 ECLAIR_MR

... ... ...

Android 1.5 3 CUPCAKE

... ... ...

Page 15: Targeting Android with Qt

Android platform distribution

http://developer.android.com/resources/dashboard/platform-versions.html

Page 16: Targeting Android with Qt

A possible future for Qt

Page 17: Targeting Android with Qt

1.6 “Donut”● Acer Liquid A1● September 2009● Linux kernel 2.6.29

Photo: flickr.com/quinnanya/CC / Some rights reserved

Page 18: Targeting Android with Qt

Necessitas

Necessitas is a community port of Qt for Android. Its founder and main developer is BogDan Vatra.

Page 19: Targeting Android with Qt

Installing Necessitas

● OpenJDK (and Ant)

● Necessitas 0.3 (3rd alpha)

http://bit.ly/qtand03 ● Linux

● not root

Page 20: Targeting Android with Qt

Default values are OK

Page 21: Targeting Android with Qt

Included components

Android SDKAndroid NDKQt, QtWebKit, QtMobilityQt Creatorgdb / gdbserverAntJDK

Page 22: Targeting Android with Qt

Adding an emulator

Page 23: Targeting Android with Qt

Getting a USB connection

● Enable USB debugging● Settings->Applications->Development

● Check connectioncd android-sdk/platform-tools./adb devices

304D1...6203B05E device???????????????? no permissions

● Restart if neededsudo ./adb kill-serversudo ./adb devices

Page 24: Targeting Android with Qt

Install Ministro / Ministro 2

Page 25: Targeting Android with Qt

A “Hello Qt Quick” example

● Qt Quick Project → Qt Quick Application● Name

● Target (Android / armv5)

● Next/Next/Next

● Add QtDeclarative

● Press Ctrl-R

Page 26: Targeting Android with Qt

Let's do it for real

Page 27: Targeting Android with Qt

Our “funky” main.qmlimport QtQuick 1.0

Rectangle { anchors.fill: parent gradient: Gradient { GradientStop { position: 0.0; color: "red" } GradientStop { position: 0.33; color: "yellow" } GradientStop { position: 1.0; color: "green" } } Rectangle { id:ball; width:100; height:100; radius: 50 color:"black" Behavior on x { PropertyAnimation{ duration:500; easing.type: Easing.OutBounce} } Behavior on y { PropertyAnimation{ duration:500; easing.type: Easing.OutBounce} } } MouseArea { anchors.fill: parent onClicked: { ball.x=mouse.x ball.y=mouse.y } }}

Page 28: Targeting Android with Qt

Psychedelic bouncy ball

Page 29: Targeting Android with Qt

Added files explained

In addition to the .pro and .h/.cpp files:android/AndroidManifest.xmlandroid/build.xmlandroid/res/*android/src/.../ministro/*android/src/.../origo/Qt*

Page 30: Targeting Android with Qt

How does it really work?

Page 31: Targeting Android with Qt

Necessitas status

● SDK (almost) complete for

● Windows, Linux and Mac

● Qt Creator

● Deploy libraries and app

● Run app

● Debug app

● Signs the app

Page 32: Targeting Android with Qt

Popularity of Necessitas

● ~10000 downloads of 0.2.1 (2nd alpha)

● ~3200 downloads of 0.3 so far (3rd alpha)

● ~5000 views of my Münich slides

Page 33: Targeting Android with Qt

Necessitas roadmap

● Alpha3 (just released!)● Lots of fixes● Signing for Android Market● OpenGL etc.● ...

● Alpha4● Android Style● Menu integration● ...

● Beta● Refactor Java wrapper code● Promise BIC● …?

Page 34: Targeting Android with Qt

Porting an actual app

Nokia N9 / Nokia 700Samsung Galaxy S2

Page 35: Targeting Android with Qt

Changes needed

● Use the right QML file and showFullScreen()

● Hack around font issue

● Add app icons

● Set package name

● Set minSdkVersion

Page 36: Targeting Android with Qt

QML and showFullScr...

--- a/main.cpp

+++ b/main.cpp

@@ -50,14 +56,16 @@ int main(int argc, char *argv[])

-#elif defined (Q_OS_SYMBIAN)

+#elif defined (Q_OS_ANDROID) || defined(Q_OS_SYMBIAN)

view.setSource(QUrl("qrc:/qml/Main.qml"));

view.showFullScreen();

#else

Page 37: Targeting Android with Qt

Font hack

--- a/main.cpp

+++ b/main.cpp

@@ -29,6 +29,12 @@ int main(int argc, char *argv[])

application.setOrganizationDomain("cutehacks.com");

application.setOrganizationName("Cutehacks");

+#if defined(Q_OS_ANDROID)

+ QFont boldFont = application.font();

+ boldFont.setBold(true);

+ application.setFont(boldFont);

+#endif

Page 38: Targeting Android with Qt

Setting app icons

commit a91fa2461ced0e75270b71c41ee80309e0697777

Author: Espen Riskedal <[email protected]>

Date: Sun Oct 9 22:17:31 2011 +0200

added proper icons where it counts

android/res/drawable-hdpi/icon.png

android/res/drawable-ldpi/icon.png

android/res/drawable-mdpi/icon.png

Page 39: Targeting Android with Qt

Setting package name

--- a/android/AndroidManifest.xml

+++ b/android/AndroidManifest.xml

@@ -1,5 +1,5 @@

<?xml version='1.0' encoding='utf-8'?>

-<manifest package="eu.licentia.necessitas...

+<manifest package="com.cutehacks.fly" ...

Page 40: Targeting Android with Qt

Setting minSdkVersion

--- a/android/AndroidManifest.xml

+++ b/android/AndroidManifest.xml

@@ -14,4 +14,5 @@

<supports-screens android:largeScreens="t...

<uses-permission android:name="android.pe...

<uses-permission android:name="android.pe...

+ <uses-sdk android:minSdkVersion="7"/>

</manifest>

Page 41: Targeting Android with Qt

3.x “Honeycomb”● Motorola Xoom● February 2011● Linux kernel 2.6.36

Photo: flickr.com/quinnanya/CC / Some rights reserved

Page 42: Targeting Android with Qt

Publishing to Android Market

Sometimes the easy part is writing the app. The hard part is getting it published.

Page 43: Targeting Android with Qt

.APK format explained

● .JAR and .ZIP● Typically includes:

META-INF/ res/ AndroidManifest.xml classes.dex resources.arsc

● Native apps also include: libs/armeabi/

Page 44: Targeting Android with Qt

Two publishing options

Ministro

+ dev friendly

+ updates

+ multiple archs

+ space / bandwidth

- UX

- updates

- BIC

Bundling Qt

+ UX

+ BIC

+ custom fixes

- space / bandwidth

- less archs

- no updates

Page 45: Targeting Android with Qt

Bundling Qt with your app

Target one arch (ARMv5)

Set relatively high API level

Only include the actually needed libs

Disable Ministro dependencies

Beware of SSL certs

Here be dragons :-)

Page 46: Targeting Android with Qt

Publishing with Ministro

cd android/

ant release

This produces Fly-unsigned.apk in the

shadowbuild directory.

Page 47: Targeting Android with Qt

Getting an A.M. account

http://market.android.com/publish

You'll need:

A credit card with 25USD

A phone number

Page 48: Targeting Android with Qt

Name, email and phone

Page 49: Targeting Android with Qt

Paying

Page 50: Targeting Android with Qt

Credit-card needed

Page 51: Targeting Android with Qt

One time fee of 25USD

Page 52: Targeting Android with Qt

Order sent

Page 53: Targeting Android with Qt

Distribution agreement

Page 54: Targeting Android with Qt

We can publish free apps!

Page 55: Targeting Android with Qt

Sign up for merchant

Page 56: Targeting Android with Qt

We can make money!

Page 57: Targeting Android with Qt

Signing the .APK

Create keykeytool -genkey -v -keystore cutehacks-release-key.keystore -alias cutehackskeystore -keyalg RSA -keysize 2048 -validity 10000

Sign packagejarsigner -verbose -keystore cutehacks-release-key.keystore android/bin/Fly-unsigned.apk cutehackskeystore

Page 58: Targeting Android with Qt

Verifying the signature

Verify signaturejarsigner -verify -verbose Fly-unsigned.apk 585 Tue ... META-INF/MANIFEST.MF 706 Tue ... META-INF/CUTEHACK.SF 1327 Tue ... META-INF/CUTEHACK.RSAsm 2932 Tue ... AndroidManifest.xmlsm 1500 Tue ... resources.arscsm 3064 Tue ... res/drawable-hdpi/icon.pngsm 1543 Tue ... res/drawable-ldpi/icon.pngsm 2347 Tue ... res/drawable-mdpi/icon.pngsm 86680 Tue ... classes.dexsm 164020 Tue ... lib/armeabi/libfly.so s = signature was verified m = entry is listed in manifest

Rename Fly-unsigned.apk to Fly-release.apk

Page 59: Targeting Android with Qt

Actually publishing

http://market.android.com/publish

You'll need:

Signed APK (max 50MB)

High-res app icon (512x512)

Two screenshots (min 320x480)

Title & Description

Page 60: Targeting Android with Qt

Upload .APK

Page 61: Targeting Android with Qt

Set name and screenshots

Page 62: Targeting Android with Qt

In the store

Page 63: Targeting Android with Qt

Installation UX with Ministro

Press app

Press “FREE”

Press “OK”

Page 64: Targeting Android with Qt

Installation UX with Ministro

Press app

Press “Yes”

Press “Ministro”

Page 65: Targeting Android with Qt

Installation UX with Ministro

Press “Install”

Press “Accept”

Press “Yes”

Page 66: Targeting Android with Qt

Installation UX with Ministro

Page 67: Targeting Android with Qt

2.0/2.1 “Eclair”● Motorola Droid● October 2009● Linux kernel 2.6.29

Photo: flickr.com/quinnanya/CC / Some rights reserved

Page 68: Targeting Android with Qt

Conclusion

Let's summarize and look at the future.

Page 69: Targeting Android with Qt

Summary

Qt on mobile: Potential bright future

Necessitas: Out-of-the-box with rough edges

Android Market: Quick and easy

Page 70: Targeting Android with Qt

Qt's future

Qt 5 – Qt Quick and scenegraph

“The next billion”

iOS and BBX

Open Governance

Page 71: Targeting Android with Qt

Information on Necessitas

Mailinglist for users:http://groups.google.com/group/android-qt

Mailinglist for devs/contributors:https://mail.kde.org/mailman/listinfo/necessitas-devel

Repositories:http://community.kde.org/Necessitas/Repositories

Wiki:http://sourceforge.net/p/necessitas/home/necessitas/

Page 72: Targeting Android with Qt

It's already possible

Fly inAndroid Market

Fly installedon phone

http://bit.ly/cuteflyhttps://market.android.com/details?id=com.cutehacks.fly

Page 73: Targeting Android with Qt

Questions?

Thank you!

@snowpong (Twitter)