Add reference to CMake project in Android Studio

Alexandru Irimiea 08/29/2015. 3 answers, 2.719 views
android-studio android-studio gradle android-ndk android-ndk cmake

In my particular case, I implemented a cross platform project in C++11 that uses CMake. I initially designed this project to work on PC (Windows, Unix), but now I realized that I can use it on mobile platforms too, without re-implementing the business logic on every platform. The project uses standard libraries: Boost, Poco, OpenSSL, Protobuf.

After a few searches I came to conclusion that this is not even an usual mode to put together native and managed code in Android.

  1. Is it possible to add reference in a Gradle project in Android Studio to a native project that uses CMake?

  2. Can NDK adopt the project in a simple manner if I compile everything in command line (assuming I don't use Android Studio)?

  3. If it is possible, is it recommended at all?

3 Answers


abhie 05/30/2016.

Is it possible to add reference in a Gradle project in Android Studio to a native project that uses CMake?

Since Google announced Android Studio 2.2 that comes with cmake plugin, so it's possible to reference CMake project to android project. I have tried that and i posted it on my blog.

Can NDK adopt the project in a simple manner if I compile everything in command line (assuming I don't use Android Studio)?

In my experience, i compile NDK in separate way and then link the static/shared library (.so file) to be used in android project. I used NDK while developing PDF Reader using mupdf here

Hope this helps.


Gerry 06/16/2016.

it would be possible with android studio 2.2, mainly the android plugin for gradle makes it possible. you could look at some examples in:https://github.com/googlesamples/android-ndk/tree/master-cmake

android studio directly reads-in your cmake scripts -- there is nothing like desktop systems that generate project files for their native IDEs ( Visual Studio or XCode ); so you might have to modify your existing cmake files to eventually make it to work for android studio.

as long as you build to the correct APK, command line or IDE does not matter too much. If you intend to ship source code, having your project ready with an IDE would be attractive.


NikitaFeodonit 07/25/2017.

Please see CMaker_Boost, build the Boost with the CMake at a configure time. Now it is tested on the Linux and Android, gcc and clang. This can be included to the gradle project in the Android Studio. I hope this helps.

Related questions

Hot questions

Language

Popular Tags