Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add reference to CMake project in Android Studio

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?

like image 797
Alexandru Irimiea Avatar asked Aug 29 '15 12:08

Alexandru Irimiea


People also ask

How do I build from source CMake?

In order to build CMake from a source tree on Windows, you must first install the latest binary version of CMake because it is used for building the source tree. Once the binary is installed, run it on CMake as you would any other project.

What is use of CMake in Android Studio?

CMake: an external build tool that works alongside Gradle to build your native library. You do not need this component if you only plan to use ndk-build. LLDB: the debugger Android Studio uses to debug native code. By default, LLDB will be installed alongside Android Studio.


2 Answers

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.

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.

like image 106
abhie Avatar answered Oct 04 '22 13:10

abhie


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.

like image 32
Gerry Avatar answered Oct 04 '22 12:10

Gerry