How to android development using cmake

Hello All,

We are using Visual Studio {rpfessional with CMake for our cross-platform builds. Currently, we are using “Visual Studio 17 2022” for Windows builds, “Ninja Multi-Config” for Linux/Android, and “Xcode” for macOS, iOS, etc.

This is how we are currently building libraries and applications for Android.

### Building the library

We currently have multiple kotlin and cpp files which we compile into libraries and jars.

* We generate ".a" libraries with cpp files of any layer.
* We generate ".jar" files with kotlin files of the layer which has kotlin files.

### Building the application/product

Product build should result in generating an APK. We use Gradle for generating the APK. Obviously, everything happens via CMake.

The steps followed are:

* All the cpp code (and the generated libs i.e. .a), results in a dynamic library (i.e. a .so file).
* The kotlin files would have already been compiled into the relevant .jar for the given layer.
* Then we create a folder structure which Gradle understand for the purpose of application build. This folder structure needs to have some build related files which tells gradle what all to do - i.e. build.gradle, settings.gradle etc.
* Now the .so and the .jars are copied in the right place in this folder structure
* We run the 'gradle build' command which results in the application package (apk) getting generated.


  • CMake commands are used to create the library and jar (add_library, add_jar etc).
  • CMake triggers an apk generation by brings the folders and files in the way gradle needs, and invokes gradle to build the package as a post build event.

The problem with this approach is generated project does not know anything if any dependencies needs to downloaded for building certain application. For example recently we added AppCompatActivity in our code and our build did not work and then we realized that we have to download androidx package and make it available to build the system.

Now this does not very maintainable approach for a complex project as if someone wants to access some new feature, he has to first figure out what all he/she needs and then he will download that then use it.

In contrast, if we look at Android Studio, it knows how to sync to get all dependencies. To achieve same in CMake what we should do ?

OR what is the best way to set up my cmake project for Android development ?

Any help would be greatly appreceiated.

CMake doesn’t really deal with getting dependencies all that much. Projects can use FetchContent to download (and possibly build) dependencies, but I don’t know how much this is effective for Android.

I don’t know as I don’t do Android development myself. Seems like not many here know either :confused: . Maybe an Android developer forum can help better?