You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native中FFmpegKit初始化报错:Cannot read property 'getLogLevel' of null

解决FFmpegKit初始化报错:Cannot read property 'getLogLevel' of null
  • 检查库安装完整性
    确认ffmpeg-kit-react-native已正确安装,执行对应包管理命令补装:

    # npm
    npm install ffmpeg-kit-react-native --save
    npx pod-install
    
    # yarn
    yarn add ffmpeg-kit-react-native
    npx pod-install
    

    同时检查Android的build.gradle、iOS的Podfile是否包含该库的依赖配置。

  • 调整初始化时机
    避免在Native模块未加载完成时调用FFmpegKitConfig,建议在useEffect中异步初始化:

    import { useEffect } from 'react';
    import { FFmpegKitConfig } from 'ffmpeg-kit-react-native';
    
    function App() {
      useEffect(() => {
        const initFFmpeg = async () => {
          try {
            await FFmpegKitConfig.init();
            // 初始化完成后执行视频处理逻辑
          } catch (error) {
            console.error('FFmpeg初始化失败:', error);
          }
        };
        initFFmpeg();
      }, []);
    
      // 其他组件代码
    }
    
  • 验证版本兼容性
    确保ffmpeg-kit-react-native版本与你的React Native版本匹配,若使用RN 0.70+,建议升级到最新稳定版:

    npm update ffmpeg-kit-react-native
    
  • 检查平台额外配置

    • Android:确保android/app/build.gradle中minSdkVersion ≥24,并在AndroidManifest.xml添加必要权限(如READ_EXTERNAL_STORAGE、WRITE_EXTERNAL_STORAGE)。
    • iOS:确保Info.plist添加相册访问权限描述(NSPhotoLibraryUsageDescription),且Podfile中platform :ios, '12.0'及以上。
  • 清理缓存重新构建
    执行以下命令清理缓存后重新编译项目:

    # 清理RN缓存
    npx react-native clean
    
    # iOS额外操作
    cd ios && rm -rf Pods Podfile.lock && pod install && cd ..
    
    # 重新运行项目
    npx react-native run-android # 或 run-ios
    

内容的提问来源于stack exchange,提问作者Md Monirozzaman khan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 23:05:58