CMake-only Android native bootstrap project.
In almost no circumstance should you torture yourself by using this build system. You would certainly be happier by following the orthodox way, unless you, like me, are allergic to Gradle and Android Studio. Or, you can think of this as a proof of concept, or an elaborate puzzle.
Tested on Windows, MacOS and Linux, with Android build tools 35, platform 34, NDK 26, CMake 3.29 and JDK 20.
- Install the latest Java Development Kit.
- Install the latest Android SDK build tools, platform, platform tools, command line tools and NDK using sdkmanager or the Android Studio built-in GUI.
- Install the latest CMake.
- Install Ninja, Make or some other Clang-compatible build system.
- Set the
ANDROID_SDK_DIR
and theJDK_DIR
environment variables (or pass them directly to CMake later). - Clone this repository:
git clone https://github.com/francescozoccheddu/androidpp
cd androidpp
I suggest using Visual Studio Code.
The repository comes with VS Code extension recomendations and preconfigured launch and debug tasks.
You can probably get the debugger working with an old NDK by injecting a "Dynamic Shared Library (Android)"
into CMakeLists.txt
with include_external_msproject
,
but there is a limit on how much ugliness I can handle, so you'll have to deal with it on your own for now.
- Configure CMake:
mkdir build
cd build
cmake ..
- Build:
cmake --build .
- Enjoy your
signed.apk
APK file. 😁
Note
You may as well want to remove the VS Code configuration logic in CMakeLists.txt
and the .vscode
directory.
CMakeLists.txt
configures the following targets:
java
: This target builds the Java code insideandroid/java
into a JAR.lib
: This target builds the C++20 code insidesrc
into a shared library.package
: This target packages the compiled Java and C++ code,android/res
,android/assets
andandroid/AndroidManifest.xml
into a signed APK.