Search code examples
androidc++iosandroid-libraryios-library

Is it possible to write a C++ library that could be used in iOS and Android Native projects?


I want to write an app for both platforms, and I want it to be a native.

Still, I would like to have a write once run anywhere conception. Since the business logic would take a huge part of an app. And it would be pretty simple regarding frameworks (mostly math calculations). I would like to move it into the common part of the app.

So my question is, are there any successful examples on C++ library that could be used for both native platforms?


Solution

  • Yes it is possible as iOS is capable of running c++ files and libraries and via the NDK Android is also capable of running c++ and c++ libraries.

    There are plenty of resources online but you might find the following from Medium useful:

    https://medium.com/safetycultureengineering/how-to-build-a-shared-c-library-for-ios-and-android-a3817aba5798

    Be careful though as there will be a performance overhead and you have to be careful when compiling the builds if you want it to run on both an iOS device and also the simulator, you will need to create a fat binary as they are built on different chip architectures.