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
- Host: GitHub
- URL: https://github.com/retifrav/android-cpp-example
- Owner: retifrav
- License: gpl-3.0
- Created: 2024-02-04T13:20:48.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-24T15:55:06.000Z (over 2 years ago)
- Last Synced: 2024-05-01T21:33:00.932Z (about 2 years ago)
- Topics: android, cpp, kotlin
- Language: Kotlin
- Homepage:
- Size: 3.58 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
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'`.