{"id":39911899,"url":"https://github.com/bowserf/android-cmake-sample","last_synced_at":"2026-01-18T16:31:17.108Z","repository":{"id":57829078,"uuid":"182087479","full_name":"bowserf/android-cmake-sample","owner":"bowserf","description":"Android and CMake sample - learn how to compile native code inside an Android app with CMake","archived":false,"fork":false,"pushed_at":"2022-06-03T13:05:11.000Z","size":144,"stargazers_count":59,"open_issues_count":0,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-03-25T19:27:20.239Z","etag":null,"topics":["android","cmake","ndk"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bowserf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-18T12:53:27.000Z","updated_at":"2024-03-01T19:21:46.000Z","dependencies_parsed_at":"2022-08-24T12:20:59.930Z","dependency_job_id":null,"html_url":"https://github.com/bowserf/android-cmake-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bowserf/android-cmake-sample","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowserf%2Fandroid-cmake-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowserf%2Fandroid-cmake-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowserf%2Fandroid-cmake-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowserf%2Fandroid-cmake-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bowserf","download_url":"https://codeload.github.com/bowserf/android-cmake-sample/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowserf%2Fandroid-cmake-sample/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28541537,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T14:59:57.589Z","status":"ssl_error","status_checked_at":"2026-01-18T14:59:46.540Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","cmake","ndk"],"created_at":"2026-01-18T16:31:17.009Z","updated_at":"2026-01-18T16:31:17.101Z","avatar_url":"https://github.com/bowserf.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NDK version](https://img.shields.io/static/v1.svg?label=NDK\u0026message=version%2019\u0026color=blue)]()\n[![CMake version](https://img.shields.io/static/v1.svg?label=CMake\u0026message=3.6.0\u0026color=red)]()\n\n# Android \u0026 CMake sample\n\nPut his hands in the native code (C/C++) with the Android NDK can be a hard task for an Android developer used to\nJava/Kotlin and Gradle.\n\nThis sample shows several use cases about how to use CMake:\n- to build native library without Android Studio\n- to use prebuilt library (shared (.so) or static (.a))\n- to depends on another native module from your native module\n- to build Android application with native code.\n\n## Project\n\nThe application allows you to do some computations on 2 numbers given in input. Computations are\nrealized by native libraries, written in C/C++, embedded in the application. Each computation\nis realized by one of the library and each library is imported in a different way using CMake.\n\nThe project contains 4 modules:\n- app\n- subdirectory\n- shared_library\n- static_library\n\n### Modules\n\nThe `app` module contains the Android application code and depends on other modules to do\ncomputations.\n\nOther modules contains C/C++ code and each one does one different computation:\n- `subdirectory` does a multiplication on 2 numbers.\n- `shared_library` does an addition on 2 numbers.\n- `static_library` does a subtraction on 2 numbers.\n\n#### App module\n\nThis module contains the code of the Android application. It contains Kotlin code to manage a basic\nAndroid application but also C/C++ code to communicate with the native libraries this application\ndepends on.\n\nDependencies on native libraries are defined in the CMakeList targeted by the `build.gradle` of the\nmodule:\n\n```\nexternalNativeBuild {\n    cmake {\n        path \"src/main/cpp/CMakeLists.txt\"\n    }\n}\n```\n\nThe C/C++ code uses JNI to create a bridge between Kotlin code and pure C/C++ code. It allows to\nwrite functions which are called by Kotlin code and from inside JNI function, to call any C/C++\nfunction.\n\n\n#### Subdirectory module\n\nThis module is imported by the `app` module with a CMake dependency. The CMakeList used by the `app`\nmodule targets the CMakeList of this module with the command `add_subdirectory`.\n\nThe library is built as a shared library. A `.so` file is generated and contains all the code.\n\nThe `include` directory contains all `public` headers required by the `app` module to be able to use\nit.\n\nThe library exposes its headers by using `target_include_directories` with `PUBLIC` visibility.\n\n\n#### Shared_library module\n\nThis module allows to generate a shared library, a `.so` file, by executing the `library_built.sh`\nscript.\n\nThis module is not built each time the `app` module is built. `app` module only targets the\npre-generated `.so` file and its headers inside the `include` directory.\n\nTo import headers in the `app` module, we use the command `include_directories`\n\n\n#### Static_library module\n\nThis module allows to generate a static library, a `.a` file, by executing the `library_built.sh`\nscript.\n\nThis module is not built each time the `app` module is built. `app` module only targets the\npre-generated `.a` file and its headers inside the `include` directory.\n\nTo import headers in the `app` module, we use the command `include_directories`\n\n\n## Resources:\n\n- [Android NDK guides](https://developer.android.com/ndk/guides)\n- [Android NDK roadmap](https://android.googlesource.com/platform/ndk/+/master/docs/Roadmap.md)\n- [Configure CMake from developer android web site](https://developer.android.com/studio/projects/configure-cmake)\n- [Configure CMake from android ndk web site](https://developer.android.com/ndk/guides/cmake)\n- [CMake changelog](https://cmake.org/cmake/help/latest/release/index.html)\n- [Codelab to create a Hello-CMake](https://codelabs.developers.google.com/codelabs/android-studio-cmake/index.html#0)\n- [Android NDK samples](https://github.com/googlesamples/android-ndk/tree/master)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowserf%2Fandroid-cmake-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbowserf%2Fandroid-cmake-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowserf%2Fandroid-cmake-sample/lists"}