Open source speech codec designed for communications quality speech between 700 and 3200 bit/s. The main application is low bandwidth HF/VHF digital radio.
This repository contains the JNI (Java Native Interface) wrapper and build scripts to compile the Codec2 library for Android. It was developed to support the Voice Burst feature in the Meshtastic Android application.
This module has been isolated in its own repository and licensed under LGPL-2.1 to maintain strict compliance with the original Codec2 library licensing terms, allowing it to be dynamically linked by the GPLv3 Meshtastic application without licensing conflicts.
This standalone library does not contain the core Android App code. It is responsible solely for:
- Downloading the upstream Codec2 C source (v1.2.0).
- Patching and executing CMake for the
arm64-v8aandx86_64Android ABIs. - Compiling the JNI wrapper (
cpp/codec2_jni.cpp) which acts as the bridge between Android's Kotlin/JVM layer and the native C layer. - Exporting the
libcodec2.soandlibcodec2_jni.sobinary files.
To ensure compatibility with modern Android 15 devices that enforce 16 KB page sizes, the script explicitly passes -Wl,-z,max-page-size=16384 to the linker.
- Android Studio or Command Line Tools installed.
- Android NDK (r25+ recommended).
- CMake installed via Android SDK Tools.
- Git for Windows/Linux/macOS.
Run the automated build script:
cd scripts/
bash build_codec2.shThe script will automatically:
- Fetch Codec2 upstream.
- Cross-compile
libcodec2.sovia Android CMake toolchains. - Compile
libcodec2_jni.sousingc++_staticto avoid missing libc++ dependencies on the target Android devices. - Output the
.sofiles for each ABI.
After the build, copy the generated .so files into the jniLibs/ directory of your Android application.
In the Meshtastic-Android fork, these .so files are bundled in the jniLibs directory, and dynamically loaded at runtime using:
System.loadLibrary("codec2_jni")This project is licensed under the LGPL-2.1 license.
See the LICENSE file for details.
