An open API service indexing awesome lists of open source software.

https://github.com/retifrav/android-cpp-example

An example of using a C++ library inside Android application with Kotlin
https://github.com/retifrav/android-cpp-example

android cpp kotlin

Last synced: 2 months ago
JSON representation

An example of using a C++ library inside Android application with Kotlin

Awesome Lists containing this project

README

          

# Android C++ example

An example of using a pre-built C++ library in Android application with Kotlin.

More details in the [following article](https://decovar.dev/blog/2024/02/12/cpp-library-in-android-application/).

- [Building C++ library](#building-c-library)
- [Running Android application](#running-android-application)

## Building C++ library

``` sh
$ cd ./cpp
$ mkdir build && cd $_

$ export ANDROID_NDK_VERSION='25.1.8937393'
$ export ANDROID_NDK_HOME="$HOME/Library/Android/sdk/ndk/$ANDROID_NDK_VERSION"

$ echo $VCPKG_ROOT

$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="../install" \
-DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" \
-DVCPKG_TARGET_TRIPLET="arm64-android-v8a-v30" \
-DVCPKG_OVERLAY_TRIPLETS="/ABSOLUTE/PATH/TO/cpp/misc/vcpkg/triplets" \
-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=30 \
..
$ cmake --build . --target install

$ cp -an ./vcpkg_installed/arm64-android-v8a-v30/* ../install/
$ ls -L1 ../install/
```

## Running Android application

1. Open `./android` folder in Android Studio;
2. Set `CMAKE_PREFIX_PATH` to `/ABSOLUTE/PATH/TO/cpp/install` in `./android/app/build.gradle.kts`;
3. Make/build the project or just click `Run 'app'`.