Android & iOS on the edge of Qt and Java/Objective-C Maciej - - PowerPoint PPT Presentation

android ios on the edge of qt and java objective c
SMART_READER_LITE
LIVE PREVIEW

Android & iOS on the edge of Qt and Java/Objective-C Maciej - - PowerPoint PPT Presentation

Android & iOS on the edge of Qt and Java/Objective-C Maciej Wglarczyk Android & iOS on the edge of Qt and Java/Objective-C About me Cracow, Poland Graduated from AGH-UST with MSc in CS 6+ Qt years Game industry


slide-1
SLIDE 1

Android & iOS – on the edge of Qt and Java/Objective-C

Maciej Węglarczyk

slide-2
SLIDE 2

Android & iOS – on the edge of Qt and Java/Objective-C About me

  • Cracow, Poland
  • Graduated from AGH-UST with MSc in CS
  • 6+ Qt years
  • Game industry
  • Ganymede Ltd. (3 years+)
  • Android & iOS lead
slide-3
SLIDE 3

The purpose of this talk

  • Explain if / why one needs to write code beyond Qt
  • Show what cannot be done with only Qt
  • Give a taste of the way to communicate with native environments
  • Give a brief overview how Qt is integrated with Android & iOS

Android & iOS – on the edge of Qt and Java/Objective-C

slide-4
SLIDE 4

Agenda

  • Reasons of extending Qt app with native code
  • Needed tools
  • Mixing Qt with Java/Objective-C
  • Adding 3rd party libraries
  • Modifying application entry point

Android & iOS – on the edge of Qt and Java/Objective-C

slide-5
SLIDE 5

Beyond Qt “It's a dangerous business, Frodo, going out of your door”

Bilbo Baggins

Android & iOS – on the edge of Qt and Java/Objective-C

slide-6
SLIDE 6

EXTENDING? WHY?

Android & iOS – on the edge of Qt and Java/Objective-C

slide-7
SLIDE 7

Importance of rich features

  • Over 1,000,000 apps available in Google Play and Apple AppStore each
  • Very demanding users
  • Different ways of monetization
  • Chances of being featured
  • Increasing user engagement
  • Virality

Android & iOS – on the edge of Qt and Java/Objective-C

slide-8
SLIDE 8

Native integration - it's actually nothing new

  • Qt Windows Extras, Qt Mac Extras, Qt X11 Extras
  • Mobile OSes are evolving faster
  • The problem is similar

Android & iOS – on the edge of Qt and Java/Objective-C

slide-9
SLIDE 9

Where to start?

  • First of all – know what you want and why
  • Check if Qt supports it
  • If not, check if it hasn't been done already by someone else...
  • ...or if it couldn't be done by someone else in near future. :)

Android & iOS – on the edge of Qt and Java/Objective-C

slide-10
SLIDE 10

What's not possible with Qt (at least for now)

  • Notifications (push, rich)
  • SMS API
  • Lock screen widgets
  • Home screen widgets
  • Google / Apple API
  • Maps
  • Game Services / Center
  • Calendar
  • ...
  • Alarms
  • Communication with other apps
  • Many useful 3rd party integrations
  • Facebook Connect
  • Google Analytics
  • Monetization libs (i.e. Chartboost)
  • ...

Android & iOS – on the edge of Qt and Java/Objective-C

slide-11
SLIDE 11

Required tools Android & iOS – on the edge of Qt and Java/Objective-C

Android

  • QtCreator
  • Some IDE for Java, i.e. Eclipse
  • Android SDK & NDK
  • Ant
  • Some devices

(emulator is still rather slow and sometimes unreliable)

iOS

  • QtCreator
  • Xcode
  • Apple Developer Program Account
  • Xcode Command Line Tools
  • Simulator is OK

(devices are better, though)

slide-12
SLIDE 12

Useful tips

  • Compile Output panel is much much more informative than Issues panel
  • Android: QtCreator's Build command builds only Qt code, not Java yet
  • Android: turn on the androiddeployqt's verbose option

Android & iOS – on the edge of Qt and Java/Objective-C

slide-13
SLIDE 13

Basic Android / iOS projects

  • Just take any of Qt's examples for given platform
  • Compile and run it from QtCreator
  • That's it

Android & iOS – on the edge of Qt and Java/Objective-C

slide-14
SLIDE 14

ADDING NATIVE CODE

Android & iOS – on the edge of Qt and Java/Objective-C

slide-15
SLIDE 15

Adding native code – Android

  • JNI – Java Native Interface
  • Encapsulated into Qt's androidextras module
  • Containing a couple of useful classes and a namespace QtAndroid

QT += androidextras QAndroidActivityResultReceiver QAndroidJniEnvironment QAndroidJniObject

Android & iOS – on the edge of Qt and Java/Objective-C

slide-16
SLIDE 16

Adding native code – Android

  • Both directions possible:
  • C++ -> Java
  • Java -> C++

<Example>

https://github.com/FenixVoltres/QtAndroidCpp2Java https://github.com/FenixVoltres/QtAndroidJava2Cpp

Android & iOS – on the edge of Qt and Java/Objective-C

slide-17
SLIDE 17

Adding native code – iOS

It's very simple:

  • Create some C++ class with normal header
  • Use Objective-C in bodies of declared methods.
  • That's all!

Android & iOS – on the edge of Qt and Java/Objective-C

slide-18
SLIDE 18

Adding native code – iOS

  • Following example taken from Richard Moe Gustavsen's

talk on Qt for iOS from last year Qt DD 13

<Example>

https://github.com/richardmg/qtdd13_qmlapp

Android & iOS – on the edge of Qt and Java/Objective-C

slide-19
SLIDE 19

How about Swift?

  • C++ code can’t be executed from Swift directly
  • Objective-C wrapper needed

Swift -> Objective-C++ -> Qt

Android & iOS – on the edge of Qt and Java/Objective-C

slide-20
SLIDE 20

ADDING NATIVE LIBRARIES

Android & iOS – on the edge of Qt and Java/Objective-C

slide-21
SLIDE 21

Adding native libraries – Android

  • Make sure you have defined ANDROID_PACKAGE_SOURCE_DIR variable in .pro file
  • Add libs folder inside and put there all jars you want
  • $PROJECT
  • android-sources
  • libs
  • <put your jar here>

<Example>

https://github.com/FenixVoltres/QtAndroidNativeLib

Android & iOS – on the edge of Qt and Java/Objective-C

slide-22
SLIDE 22

Adding native libraries – iOS

Even simpler:

LIBS += -F/path/to/frameworks/folder LIBS += -framework StoreKit Android & iOS – on the edge of Qt and Java/Objective-C

slide-23
SLIDE 23

MODYFYING ENTRY POINT

Android & iOS – on the edge of Qt and Java/Objective-C

slide-24
SLIDE 24

Why one would modify an entry point?

  • Not whole application must be written in Qt
  • To override some Qt's behavior
  • To make some actions before Qt is loaded

Android & iOS – on the edge of Qt and Java/Objective-C

slide-25
SLIDE 25

Deployment process – Android

  • A bit complicated
  • Two overrided classes – QtActivity.java and QtApplication.java

are copied to android build folder

  • Located in $QT/android_xxx/src/android/java/src/org/qtproject/qt5
  • Used in AndroidManifest.xml

Android & iOS – on the edge of Qt and Java/Objective-C

slide-26
SLIDE 26

Adding .java source files

  • Define ANDROID_PACKAGE_SOURCE_DIR variable in .pro file,

so it points to folder with Android internal folders structure (src, res, assets, libs) or let QtCreator does it for you

  • Put all .java files in proper folder structure connected with their packages

in src folder

  • Put all other resources in proper folders – all of them will be copied into

the final .apk file

Android & iOS – on the edge of Qt and Java/Objective-C

slide-27
SLIDE 27

Modifying app’s entry point – Android

  • AndroidManifest.xml can be changed – any different Activity can be an entry point.
  • QtActivity and QtApplication can be overridden

<Example>

https://github.com/FenixVoltres/QtAndroidSplash

Android & iOS – on the edge of Qt and Java/Objective-C

slide-28
SLIDE 28

Deployment process – iOS

  • Again, very simple
  • Building a project creates Xcode project file in build folder
  • It can be open an freely modified after QtCreator build.
  • After any change in QtCreator the process must be repeated!

Android & iOS – on the edge of Qt and Java/Objective-C

slide-29
SLIDE 29

Modifying app’s entry point – iOS

  • Open Xcode project generated by QtCreator
  • Modify what you want.

Android & iOS – on the edge of Qt and Java/Objective-C

slide-30
SLIDE 30

WRAP UP

Android & iOS – on the edge of Qt and Java/Objective-C

slide-31
SLIDE 31

Mixing Qt with native code

  • Much easier on iOS than on Android
  • Almost everything is possible

Good luck!

Android & iOS – on the edge of Qt and Java/Objective-C

slide-32
SLIDE 32

THANK YOU!

Android & iOS – on the edge of Qt and Java/Objective-C

slide-33
SLIDE 33

Qt& Am

Questions & Answers maybe

Android & iOS – on the edge of Qt and Java/Objective-C

Maciej Węglarczyk Maciej.Weglarczyk@gmail.com