androidx / androidx/media

Help needed with building FFMPEG extention.

Open
#2,820 2 comments 0 reactions 1 assignee View on GitHub

@microkatz is already working on this.

Since Oct 9, 2025.

bug
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Version

Media3 1.7.1 (same as 1.6.1)

More version details

I'm trying to build the FFMPEG extension using Ubuntu VM. I was closely following the README steps. I was able to complete below script successfully with .a static library generated for all ABI.

./build_ffmpeg.sh \
  "${FFMPEG_MODULE_PATH}" "${NDK_PATH}" "${HOST_PLATFORM}" "${ANDROID_ABI}" "${ENABLED_DECODERS[@]}"

ANDROID_ABI=28
NDK_PATH=$HOME/Android/ndk/29.0.14033849
ENABLED_DECODERS=(mp3)
FFMPEG Version: 6.0 & 6.1
Media: 1.7.1
NDK: 26.3.11579264 & 29.0.14033849

below tools installed.

sdkmanager "platform-tools" \
           "platforms;android-35" \
           "build-tools;35.0.1" \
           "ndk;26.3.11579264" \
           "cmake;3.22.1"

Next step is to generate AAR. when I run below command from the media root:

./gradlew lib-decoder-ffmpeg:assembleRelease

I got errors complain undefined symbol: stderr & iconv_xxx and build failed.

> Task :lib-decoder-ffmpeg:buildCMakeRelWithDebInfo[arm64-v8a]
C/C++: ninja: Entering directory `/home/ubuntu/media/libraries/decoder_ffmpeg/.cxx/RelWithDebInfo/306k171m/arm64-v8a'
C/C++: : && /home/ubuntu/Android/ndk/29.0.14033849/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --sysroot=/home/ubuntu/Android/ndk/29.0.14033849/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O2 -g -DNDEBUG  -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--no-undefined-version -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments  -Wl,--gc-sections   -Wl,-Bsymbolic -Wl,-z,max-page-size=16384 -shared -Wl,-soname,libffmpegJNI.so -o /home/ubuntu/media/libraries/decoder_ffmpeg/buildout/intermediates/cxx/RelWithDebInfo/306k171m/obj/arm64-v8a/libffmpegJNI.so CMakeFiles/ffmpegJNI.dir/ffmpeg_jni.cc.o  -landroid  /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libswresample.a  /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a  /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavutil.a  /home/ubuntu/Android/ndk/29.0.14033849/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21/liblog.so  -latomic -lm && :
C/C++: ld.lld: error: undefined symbol: stderr
C/C++: >>> referenced by log.c:380 (libavutil/log.c:380)
C/C++: >>>               log.o:(av_log_default_callback) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavutil.a
C/C++: >>> referenced by log.c:380 (libavutil/log.c:380)
C/C++: >>>               log.o:(av_log_default_callback) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavutil.a
C/C++: >>> referenced by log.c:384 (libavutil/log.c:384)
C/C++: >>>               log.o:(av_log_default_callback) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavutil.a
C/C++: >>> referenced 7 more times
C/C++: ld.lld: error: undefined symbol: iconv_open
C/C++: >>> referenced by decode.c:803 (libavcodec/decode.c:803)
C/C++: >>>               decode.o:(avcodec_decode_subtitle2) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: >>> referenced by decode.c:1631 (libavcodec/decode.c:1631)
C/C++: >>>               decode.o:(ff_decode_preinit) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: ld.lld: error: undefined symbol: iconv
C/C++: >>> referenced by decode.c:815 (libavcodec/decode.c:815)
C/C++: >>>               decode.o:(avcodec_decode_subtitle2) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: >>> referenced by decode.c:816 (libavcodec/decode.c:816)
C/C++: >>>               decode.o:(avcodec_decode_subtitle2) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: ld.lld: error: undefined symbol: iconv_close
C/C++: >>> referenced by decode.c:832 (libavcodec/decode.c:832)
C/C++: >>>               decode.o:(avcodec_decode_subtitle2) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: >>> referenced by decode.c:832 (libavcodec/decode.c:832)
C/C++: >>>               decode.o:(avcodec_decode_subtitle2) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: >>> referenced by decode.c:1638 (libavcodec/decode.c:1638)
C/C++: >>>               decode.o:(ff_decode_preinit) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: clang++: error: linker command failed with exit code 1 (use -v to see invocation)
C/C++: ninja: build stopped: subcommand failed.

> Task :lib-decoder-ffmpeg:buildCMakeRelWithDebInfo[arm64-v8a] FAILED

FAILURE: Build failed with an exception.

I just added ndkVersion in the build.gradle. nothing else modified.

// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
apply from: "$gradle.ext.androidxMediaSettingsDir/common_library_config.gradle"

android {
    namespace 'androidx.media3.decoder.ffmpeg'
    //ndkVersion '26.3.11579264'
    ndkVersion '29.0.14033849'

    // TODO(Internal: b/372449691): Remove packagingOptions once AGP is updated
    // to version 8.5.1 or higher.
    packagingOptions {
        jniLibs {
            useLegacyPackaging true
        }
    }
}

// Configure the native build only if ffmpeg is present to avoid gradle sync
// failures if ffmpeg hasn't been built according to the README instructions.
if (project.file('src/main/jni/ffmpeg').exists()) {
    android.externalNativeBuild.cmake.path = 'src/main/jni/CMakeLists.txt'
    // LINT.IfChange
    // Should match cmake_minimum_required.
    android.externalNativeBuild.cmake.version = '3.21.0+'
    // LINT.ThenChange(src/main/jni/CMakeLists.txt)
}

dependencies {
    api project(modulePrefix + 'lib-decoder')
    // TODO(b/203752526): Remove this dependency.
    implementation project(modulePrefix + 'lib-exoplayer')
    implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
    compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
    compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
    testImplementation project(modulePrefix + 'test-utils')
    testImplementation 'org.robolectric:robolectric:' + robolectricVersion
}

I tried FFMPEG 6.1 as well as latest NDK 29.0.14033849, same issue.
Any idea how to get this fixed?

Devices that reproduce the issue

Ubuntu 18.04.6 LTS
FFMPEG Version: 6.0 & 6.1
Media: 1.7.1
NDK: 26.3.11579264 & 29.0.14033849

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps
  1. Follow Build instruciton from README steps
  2. Run command from the media root: ./gradlew lib-decoder-ffmpeg:assembleRelease
Expected result

./gradlew lib-decoder-ffmpeg:assembleRelease completes succesfully with AAR file generated.

Actual result

I got errors complain undefined symbol: stderr & iconv_xxx and build failed.

> Task :lib-decoder-ffmpeg:buildCMakeRelWithDebInfo[arm64-v8a]
C/C++: ninja: Entering directory `/home/ubuntu/media/libraries/decoder_ffmpeg/.cxx/RelWithDebInfo/306k171m/arm64-v8a'
C/C++: : && /home/ubuntu/Android/ndk/29.0.14033849/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --sysroot=/home/ubuntu/Android/ndk/29.0.14033849/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -O2 -g -DNDEBUG  -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--no-undefined-version -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments  -Wl,--gc-sections   -Wl,-Bsymbolic -Wl,-z,max-page-size=16384 -shared -Wl,-soname,libffmpegJNI.so -o /home/ubuntu/media/libraries/decoder_ffmpeg/buildout/intermediates/cxx/RelWithDebInfo/306k171m/obj/arm64-v8a/libffmpegJNI.so CMakeFiles/ffmpegJNI.dir/ffmpeg_jni.cc.o  -landroid  /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libswresample.a  /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a  /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavutil.a  /home/ubuntu/Android/ndk/29.0.14033849/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21/liblog.so  -latomic -lm && :
C/C++: ld.lld: error: undefined symbol: stderr
C/C++: >>> referenced by log.c:380 (libavutil/log.c:380)
C/C++: >>>               log.o:(av_log_default_callback) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavutil.a
C/C++: >>> referenced by log.c:380 (libavutil/log.c:380)
C/C++: >>>               log.o:(av_log_default_callback) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavutil.a
C/C++: >>> referenced by log.c:384 (libavutil/log.c:384)
C/C++: >>>               log.o:(av_log_default_callback) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavutil.a
C/C++: >>> referenced 7 more times
C/C++: ld.lld: error: undefined symbol: iconv_open
C/C++: >>> referenced by decode.c:803 (libavcodec/decode.c:803)
C/C++: >>>               decode.o:(avcodec_decode_subtitle2) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: >>> referenced by decode.c:1631 (libavcodec/decode.c:1631)
C/C++: >>>               decode.o:(ff_decode_preinit) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: ld.lld: error: undefined symbol: iconv
C/C++: >>> referenced by decode.c:815 (libavcodec/decode.c:815)
C/C++: >>>               decode.o:(avcodec_decode_subtitle2) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: >>> referenced by decode.c:816 (libavcodec/decode.c:816)
C/C++: >>>               decode.o:(avcodec_decode_subtitle2) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: ld.lld: error: undefined symbol: iconv_close
C/C++: >>> referenced by decode.c:832 (libavcodec/decode.c:832)
C/C++: >>>               decode.o:(avcodec_decode_subtitle2) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: >>> referenced by decode.c:832 (libavcodec/decode.c:832)
C/C++: >>>               decode.o:(avcodec_decode_subtitle2) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: >>> referenced by decode.c:1638 (libavcodec/decode.c:1638)
C/C++: >>>               decode.o:(ff_decode_preinit) in archive /home/ubuntu/media/libraries/decoder_ffmpeg/src/main/jni/ffmpeg/android-libs/arm64-v8a/libavcodec.a
C/C++: clang++: error: linker command failed with exit code 1 (use -v to see invocation)
C/C++: ninja: build stopped: subcommand failed.

> Task :lib-decoder-ffmpeg:buildCMakeRelWithDebInfo[arm64-v8a] FAILED

FAILURE: Build failed with an exception.
Media

N/A

Bug Report
  • You will email the zip file produced by adb bugreport to android-media-github@google.com after filing this issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.