Upload
gdgut
View
427
Download
0
Embed Size (px)
Citation preview
Cross-Platform C++for TV and Mobile Apps
1/26/2016© 2016 Stephen Spann
demic apps LLC
Agenda1. Mobile C++ Overview
2. Cross-Platform C++ Architecture with Djinni
3. Other C++ Tools for Android
4. Q&A
Image Credit: Toni Rodrigo
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
Mobile C++ Overview
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
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)
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
Cross-Platform C++ Architecture
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
No one likes writing bridge code!
● Error-prone
● Hard to troubleshoot
● Little to no documentation, syntax hints, etc
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
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
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
Other Tools
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
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/
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)
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/
Contact Me
Stephen Spann*demic apps LLC
@spanndemic