20
Cross-Platform C++ for TV and Mobile Apps 1/26/2016 © 2016 Stephen Spann demic apps LLC

Mobile C++

  • Upload
    gdgut

  • View
    427

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Mobile C++

Cross-Platform C++for TV and Mobile Apps

1/26/2016© 2016 Stephen Spann

demic apps LLC

Page 2: Mobile C++

Agenda1. Mobile C++ Overview

2. Cross-Platform C++ Architecture with Djinni

3. Other C++ Tools for Android

4. Q&A

Image Credit: Toni Rodrigo

Page 3: Mobile C++

About Me

Background in web development, with iOS and Java experience 2007-2015

Began working with Cross-Platform C++ in July 2015Mobile C++ Tutorialsmobilecpptutorials.com

Cross-Platform TV App: imperson8imperson8.com

Page 4: Mobile C++

Mobile C++ Overview

Page 5: Mobile C++

What is C++?

Designed by Bjarne Stroustrup at Bell labs in 1983

Extension of the C Language (++ as in numerical increment)

Used in all sorts of applications from Robots to Gaming

Known for high performance

Page 6: Mobile C++

C++ Advantages

It’s been around a long time... yay!

Plenty of troubleshooting info on the Internet

Many open-source libraries available (OpenCV, Boost, etc)

Good for apps that have heavy use of databases, APIs, etc.

Great for new apps, cross-platform Prototypes and MVPs

Unit testing across all platforms

Utilize Native UI (better performance)

Works on TVs!

C++ known for fast performance

It’s FREE!

Be on new platforms on day 1 (tvOS, etc)

Page 7: Mobile C++

C++ Disadvantages

It’s been around a long time… boo!

Out-of-date information on the Internet

Multiple ways of accomplishing the same thing

Bad for apps that are primarily UI

Difficult to migrate existing apps

Steep learning curve

Large number of languages and tools involved

Hard sell to clients/stakeholders

Have to build UI for each platform

Page 8: Mobile C++

Who’s Doing It?

https://mobilecpp.slack.com/

Page 9: Mobile C++

Cross-Platform C++ Architecture

Page 10: Mobile C++

Cross-Platform C++ Architecture

Java

C++

Objective-C

JNI Objective-C++

“Back end” Code● SQLite Database Code● API Calls● Analytics

“Front end” Code● User Interface● Animations● Device Features

Bridge Code

Page 11: Mobile C++

No one likes writing bridge code!

● Error-prone

● Hard to troubleshoot

● Little to no documentation, syntax hints, etc

Page 12: Mobile C++

The Secret Sauce: Dropbox’s Djinni

● Configured with IDL Files (Interface Definition Language)

● Generates all needed bridge code: JNI and Objective-C++

● Creates idiomatic interfaces for C++, Java, and Objective-C

Page 13: Mobile C++

hello_world = interface +c { static create(): hello_world; get_hello_world(): string;}

Djinni in Action: C++

hello_world.hpp

helloworld.djinni

Generated by Djinni

Handwritten

C++ Interface

hello_world_impl.cpp

hello_world_impl.hpp

IDL File

C++ Implementation

Page 14: Mobile C++

hello_world = interface +c { static create(): hello_world; get_hello_world(): string;}

Djinni in Action: Java

NativeHelloWorld.hpp

helloworld.djinni

Generated by Djinni

Handwritten

JNI Bridge

IDL File

Java Interface(?)

NativeHelloWorld.cpp

HelloWorld.java

MainActivity.java Java Implementation

Page 15: Mobile C++

Other Tools

Page 16: Mobile C++

C++ Tools for Android

GYP (Generate Your Projects)● Android no longer supported● Have to write both GYP and

Make files

CMake● Ideal for making reusable libraries

Experimental Gradle Plugin● Build/include libraries and source

files all in Gradle

Android NDK● Android’s libc (Bionic) has

several bugs● Missing parts of the Standard

Libary (ex: std::thread and std::mutex)

NDK OptionsBuilding Libraries

CrystaX NDK● More C++ Support● Bug fixes

Page 17: Mobile C++

Boost C++ Libraries

http://www.boost.org/

● Peer-reviewed by the C++ Community

● Boost libraries are often incorporated into the

C++ Standard Library

Can be difficult to integrate into Android/iOS, some helpful links:

Build Script for OS X/iOS: https://gist.github.com/faithfracture

Precompiled for tvOS: https://github.com/danoli3/ofxtvOSBoost

Android 3rd-Party NDK: https://www.crystax.net/

Page 18: Mobile C++

CrystaX NDK

https://www.crystax.net/

● Drop-in replacement for Google’s Android NDK

● Includes Boost Libraries

● Built-in C++11 and C++14 Support

● Includes missing elements from the Android NDK

(ex: std::thread and std::mutex)

● Includes most recent Clang and GCC Compilers

● Fixes to bugs in Android libc (Bionic)

Page 19: Mobile C++

Where to go from here?Djinni and MX3 repos with examples:https://github.com/dropbox/djinnihttps://github.com/libmx3/mx3

Mobile C++ Tutorials:http://mobilecpptutorials.com

Mobile C++ Slack Channel:https://mobilecpp.slack.com/

CPP Con:http://cppcon.org/

Page 20: Mobile C++

Contact Me

Stephen Spann*demic apps LLC

[email protected]

@spanndemic