On both platforms, you can directly enable the precompiled library, as well as the C ++ source code.
On Android, you'll want to learn the Android NDK . This allows you to include native code in C / C ++, which can switch to Java. The relationship between Java and C / C ++ is controlled using JNI . This is a rather tedious, inconvenient system for communication between C ++ and Java. You will want to study the customization of the makefile of the Android.mk file, which indicates how to include your library (or source code) in your assembly.
On iOS, it's a little more closely connected. You may have Objective-C ++ files that can run both C ++ code and Objective-C. If you use Swift, this is a bit different (the bridge between Objective-C ++ and Swift).
In some cases, when a platform (Android / iOS) provides functionality that is superior to what is possible or realistic with C ++, you may find yourself with a code architecture so that your C ++ can reach the platform if necessary. This means that you may have headers with separate implementation files per platform.
thing.hthing_android.cppthing_ios.mm
The Android.mk Android application file will contain thing_android.cpp (but not thing_ios.mm ). This file can cross the JNI bridge to talk to Java as needed, whenever you need something from the Android SDK.
The iOS app will include thing_ios.mm (but not thing_android.cpp ). The .mm extension means Objective-C ++, so the file can directly access Cocoa's powerful libraries as needed.
Finally, on all platforms, you will either want to change your C ++ usage to the lowest common denominator platform. In other words, if iOS supports a specific C ++ function, but Android does not, then you cannot use this particular function.
drhr
source share