On both platforms, it's possible to include a precompiled library as well as C++ source code directly.
On Android, you'll want to look into using the Android NDK
. This allows you to include native C/C++ code that can bridge over to Java. The connection between Java and C/C++ is managed with the JNI
. It's a fairly tedious, awkward system for communicating between C++ and Java. You'll want to look into setting up an Android.mk
makefile that specifies how to include your library (or source code) into your build.
On iOS, it's a little more tightly linked. You can have Objective-C++ files that can run both C++ and Objective-C code. If you're using Swift, it's a little different (bridging between Objective-C++ and Swift).
In some cases, when the platform (Android/iOS) provides functionality that is superior to what is possible or realistic with C++, you might find yourself architecting the code such that your C++ can reach out to the platform as needed. This means that you might have headers with separate implementation files per platform.
thing.h
thing_android.cpp
thing_ios.mm
The android app's Android.mk
file will include thing_android.cpp
(but not thing_ios.mm
). This file could cross the JNI bridge to talk to Java as needed, whenever you need something from Android SDK.
The iOS app will include thing_ios.mm
(but not thing_android.cpp
). The .mm
extension signifies Objective-C++, so that file could directly call powerful Cocoa libraries as needed.
Finally, on all platforms, you'll want to be sure to either scale back your usage of C++ to the lowest common denominator platform. In other words, if iOS supports a particular feature of C++, and Android doesn't, then you cannot use that particular feature.