Skip to content

Android Prefab

Taner Sener edited this page Jul 28, 2026 · 1 revision

Android Prefab support is optional. Use it when an Android application needs to consume FFmpegKitNext native libraries from CMake through Android Gradle Plugin Prefab integration.

Java/Kotlin-only, Flutter and React Native applications do not need the Prefab payload.

Build an AAR With Prefab

Pass --prefab to the Android build entrypoint:

./nix-android.sh -p android-r27d --prefab

The same option can be passed to the direct build script:

./scripts/start-android.sh --prefab

The build still produces the normal local Maven repository under prebuilt, for example:

prebuilt/bundle-android-aar-24-maven/
  com/arthenica/ffmpeg-kit-next/<version>/
    ffmpeg-kit-next-<version>.aar
    ffmpeg-kit-next-<version>.pom

When --prefab is enabled, the generated AAR also contains a prefab/ payload. Do not use --no-archive for a Prefab build because the Prefab payload is injected into the generated AAR.

What the Build Adds

After the Android AAR is created, the build script stages a Prefab package and injects it into the AAR.

The package descriptor is:

{
  "schema_version": 2,
  "name": "ffmpeg-kit-next",
  "version": "<ffmpeg-kit-next-version>",
  "dependencies": []
}

The build discovers the ABIs actually present under android/libs, then creates one Prefab library entry per ABI. Each ABI entry records the ABI name, Android API level, NDK major version, selected STL and that the exported libraries are shared libraries.

The exported Prefab modules are:

avutil
swresample
swscale
avcodec
avformat
avfilter
avdevice
ffmpegkit_abidetect
ffmpegkit

FFmpeg modules use the architecture-independent FFmpeg header tree from prebuilt/android-*/ffmpeg/include. The ffmpegkit module exports ffmpegkit.h and ffprobekit.h; ffmpegkit_abidetect exports ffmpegkit_abidetect.h.

Module dependencies are encoded in Prefab metadata. For example, avformat exports avcodec and avutil, and ffmpegkit exports the FFmpeg modules it depends on.

Consume From an Android App

Add the local Maven repository produced by the build:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven {
            url "<path-to-repo>/prebuilt/bundle-android-aar-24-maven"
        }
    }
}

Enable Prefab in the consuming Android app:

android {
    buildFeatures {
        prefab true
    }

    defaultConfig {
        externalNativeBuild {
            cmake {
                arguments "-DANDROID_STL=c++_shared"
            }
        }
    }

    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }
}

Then depend on the generated AAR:

dependencies {
    implementation 'com.arthenica:ffmpeg-kit-next:<version>'
}

Consume From CMake

Android Gradle Plugin adds the AAR's Prefab package to CMake's package search path when buildFeatures.prefab = true, so the app does not need to hard-code a path to the generated AAR.

Use the package and imported targets from CMake:

find_package(ffmpeg-kit-next REQUIRED CONFIG)

add_library(native-test SHARED native-test.c)

target_link_libraries(native-test
    ffmpeg-kit-next::avformat
    ffmpeg-kit-next::avcodec
    ffmpeg-kit-next::avfilter
    ffmpeg-kit-next::avdevice
    ffmpeg-kit-next::avutil)

Link the modules your native code uses directly. Prefab metadata propagates the module dependencies declared by the package, but it is still clearer to link the FFmpeg libraries referenced by your own source.

Test App

The FFmpegKitNext Test repository includes a dedicated Android native test application named test-app-native.

That app:

  • Enables buildFeatures.prefab = true
  • Consumes the local Maven repository from ../ffmpeg-kit-next/prebuilt/bundle-android-aar-24-maven
  • Uses find_package(ffmpeg-kit-next REQUIRED CONFIG)
  • Links directly against exported targets such as ffmpeg-kit-next::avformat, ffmpeg-kit-next::avcodec, ffmpeg-kit-next::avfilter, ffmpeg-kit-next::avdevice and ffmpeg-kit-next::avutil
  • Calls FFmpeg native APIs from C to verify headers, link resolution, runtime library loading, probing and synthetic encoding

From the test repository, build it with Gradle:

cd android
./gradlew :test-app-native:assembleDebug

Clone this wiki locally