Skip to content

francescozoccheddu/androidpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

androidpp

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.

Installation

  1. Install the latest Java Development Kit.
  2. Install the latest Android SDK build tools, platform, platform tools, command line tools and NDK using sdkmanager or the Android Studio built-in GUI.
  3. Install the latest CMake.
  4. Install Ninja, Make or some other Clang-compatible build system.
  5. Set the ANDROID_SDK_DIR and the JDK_DIR environment variables (or pass them directly to CMake later).
  6. Clone this repository:
git clone https://github.com/francescozoccheddu/androidpp
cd androidpp

Usage

I suggest using Visual Studio Code.

Visual Studio Code

The repository comes with VS Code extension recomendations and preconfigured launch and debug tasks.

Visual Studio

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.

Command line

  1. Configure CMake:
mkdir build
cd build
cmake .. 
  1. Build:
cmake --build .
  1. 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.

Targets

CMakeLists.txt configures the following targets:

  • java: This target builds the Java code inside android/java into a JAR.
  • lib: This target builds the C++20 code inside src into a shared library.
  • package: This target packages the compiled Java and C++ code, android/res, android/assets and android/AndroidManifest.xml into a signed APK.