{"record":{"id":"4c4125a56355acfb","repo":"DrKLO/Telegram","slug":"failed-to-load-decoder-native-libraries","errorCode":null,"errorMessage":"Failed to load decoder native libraries.","messagePattern":"Failed to load decoder native libraries\\.","errorType":"exception","errorClass":"FfmpegDecoderException","httpStatus":null,"severity":"critical","filePath":"TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java","lineNumber":61,"sourceCode":"  @Nullable private final byte[] extraData;\n  private final @C.PcmEncoding int encoding;\n  private final int outputBufferSize;\n\n  private long nativeContext; // May be reassigned on resetting the codec.\n  private boolean hasOutputFormat;\n  private volatile int channelCount;\n  private volatile int sampleRate;\n\n  public FfmpegAudioDecoder(\n      Format format,\n      int numInputBuffers,\n      int numOutputBuffers,\n      int initialInputBufferSize,\n      boolean outputFloat)\n      throws FfmpegDecoderException {\n    super(new DecoderInputBuffer[numInputBuffers], new SimpleDecoderOutputBuffer[numOutputBuffers]);\n    if (!FfmpegLibrary.isAvailable()) {\n      throw new FfmpegDecoderException(\"Failed to load decoder native libraries.\");\n    }\n    Assertions.checkNotNull(format.sampleMimeType);\n    codecName = Assertions.checkNotNull(FfmpegLibrary.getCodecName(format.sampleMimeType));\n    extraData = getExtraData(format.sampleMimeType, format.initializationData);\n    encoding = outputFloat ? C.ENCODING_PCM_FLOAT : C.ENCODING_PCM_16BIT;\n    outputBufferSize = outputFloat ? OUTPUT_BUFFER_SIZE_32BIT : OUTPUT_BUFFER_SIZE_16BIT;\n    nativeContext =\n        ffmpegInitialize(codecName, extraData, outputFloat, format.sampleRate, format.channelCount);\n    if (nativeContext == 0) {\n      throw new FfmpegDecoderException(\"Initialization failed.\");\n    }\n    setInitialInputBufferSize(initialInputBufferSize);\n  }\n\n  @Override\n  public String getName() {\n    return \"ffmpeg\" + FfmpegLibrary.getVersion() + \"-\" + codecName;\n  }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/com/google/android/exoplayer2/ext/ffmpeg/FfmpegAudioDecoder.java#L43-L79","documentation":"FfmpegAudioDecoder's constructor throws FfmpegDecoderException('Failed to load decoder native libraries.') when FfmpegLibrary.isAvailable() is false — meaning the FFmpeg native (.so) libraries were not packaged or could not be loaded by the app. This is a hard precondition: without the native libs the decoder cannot run, so it fails before any codec initialization.","triggerScenarios":"Constructing FfmpegAudioDecoder (typically via DefaultRenderersFactory with extension extension enabled) on an APK that does not include the FFmpeg native libraries for the current ABI.","commonSituations":"The FFmpeg extension AAR/.so files are absent from the build; the device's ABI is not among the packaged ABIs (abiFilters); ProGuard/R8 stripping JNI symbols; shipping a release APK without the FFmpeg JNI native libs.","solutions":["Package the FFmpeg native libraries for all target ABIs (build the FFmpeg extension and include its .so outputs in jniLibs).","Verify FfmpegLibrary.isAvailable() before enabling FFmpeg-backed playback; fall back to a platform decoder otherwise.","Check abiFilters includes the device's ABI and that packaging did not exclude the libs."],"exampleFix":"// before\nif (FfmpegLibrary.isAvailable()) { /* never reached */ }\n\n// after\nandroid {\n  defaultConfig { ndk { abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64' } }\n}","handlingStrategy":"validation","validationCode":"// guard on library availability before enabling FFmpeg renderer\nif (FfmpegLibrary.isAvailable()) {\n  renderers.add(new FfmpegAudioRenderer(...));\n} else { /* rely on platform decoders */ }","typeGuard":null,"tryCatchPattern":"try { new FfmpegAudioDecoder(format, nIn, nOut, bufSize, outputFloat); }\ncatch (FfmpegDecoderException e) { /* fall back to MediaCodec */ }","preventionTips":["Package FFmpeg native libs for all target ABIs.","Check FfmpegLibrary.isAvailable() before selecting the FFmpeg renderer.","Verify abiFilters and packaging preserve the .so files."],"tags":["audio","exoplayer","ffmpeg","native-library","jni","build"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}