Download - Mobile C++
![Page 1: Mobile C++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/1.jpg)
Cross-Platform C++for TV and Mobile Apps
1/26/2016© 2016 Stephen Spann
demic apps LLC
![Page 2: Mobile C++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/2.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/3.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/4.jpg)
Mobile C++ Overview
![Page 5: Mobile C++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/5.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/6.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/7.jpg)
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 9: Mobile C++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/9.jpg)
Cross-Platform C++ Architecture
![Page 10: Mobile C++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/10.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/11.jpg)
No one likes writing bridge code!
● Error-prone
● Hard to troubleshoot
● Little to no documentation, syntax hints, etc
![Page 12: Mobile C++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/12.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/13.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/14.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/15.jpg)
Other Tools
![Page 16: Mobile C++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/16.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/17.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/18.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/19.jpg)
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++](https://reader031.vdocuments.us/reader031/viewer/2022030303/587b45191a28ab9c0e8b68a7/html5/thumbnails/20.jpg)
Contact Me
Stephen Spann*demic apps LLC
@spanndemic