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

Expo裸项目react-native-webrtc构建:DSO与EGL14错误循环求助

Expo裸项目react-native-webrtc构建错误循环解决方案

问题背景

开发Expo裸项目的react-native-webrtc应用时,陷入以下构建错误循环:

  • 初始触发DSO加载错误,通过自定义插件添加android.packagingOptions.jniLibs.useLegacyPackaging = true后解决,但随即出现No static method createEGl14错误
  • 将minSdkVersion升级至24后,DSO问题再次复现
  • 环境:JDK 11,未使用EAS构建

解决方案步骤

1. 修正自定义插件的Gradle配置插入方式

原插件直接在build.gradle末尾追加配置,导致packagingOptions处于android块外部,配置无效。修改插件,将配置插入到android块内部:

const {
  createRunOncePlugin,
  withAppBuildGradle,
} = require("@expo/config-plugins");

const withAppBuildGradleModified = (config) => {
  return withAppBuildGradle(config, async (file) => {
    let contents = file.modResults.contents;
    // 检查是否已添加配置,避免重复插入
    if (!contents.includes('packagingOptions')) {
      // 找到android块的起始位置,插入packagingOptions配置
      const androidBlockRegex = /android\s*{/;
      contents = contents.replace(androidBlockRegex, `android {
    packagingOptions {
        jniLibs {
            useLegacyPackaging = true
        }
    }`);
    }
    file.modResults.contents = contents;
    return file;
  });
};

module.exports = createRunOncePlugin(
  withAppBuildGradleModified,
  "withAppBuildGradleModified",
  "1.0.0"
);

2. 统一NDK版本适配minSdk 24

将NDK版本统一设置为24(适配minSdk 24及所有架构),避免因架构差异导致的DSO加载问题:

buildscript {
    ext {
        buildToolsVersion = findProperty('android.buildToolsVersion') ?: '31.0.0'
        minSdkVersion = 24
        compileSdkVersion = Integer.parseInt(findProperty('android.compileSdkVersion') ?: '31')
        targetSdkVersion = Integer.parseInt(findProperty('android.targetSdkVersion') ?: '31')
        if (findProperty('android.kotlinVersion')) {
            kotlinVersion = findProperty('android.kotlinVersion')
        }
        frescoVersion = findProperty('expo.frescoVersion') ?: '2.5.0'
        // 统一使用NDK 24,适配minSdk 24和全架构
        ndkVersion = '24.0.8215888'
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:7.2.1')
        classpath('com.facebook.react:react-native-gradle-plugin')
        classpath('de.undercouch:gradle-download-task:5.0.1')
    }
}

def REACT_NATIVE_VERSION = new File(['node', '--print', "JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())

allprojects {
    configurations.all {
        resolutionStrategy {
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }

    repositories {
        mavenLocal()
        maven {
            url(new File(['node', '--print', "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), '../android'))
        }
        maven {
            url(new File(['node', '--print', "require.resolve('jsc-android/package.json')"].execute(null, rootDir).text.trim(), '../dist'))
        }

        google()
        mavenCentral {
            content {
                excludeGroup 'com.facebook.react'
            }
        }
        maven { url 'https://www.jitpack.io' }
    }
}

3. 清理缓存并重新构建

完成配置修改后,执行以下步骤确保缓存清理干净:

  • 进入Android目录,运行./gradlew clean
  • 删除项目根目录的node_modules和package-lock.json,执行npm install重新安装依赖
  • 运行npx expo prebuild --clean重新生成Expo原生配置文件
  • 重新尝试构建项目

说明

app.json配置无需调整,保持原有插件顺序即可:

{
  "expo": {
    "name": "videocall_webrtc",
    "slug": "videocall_webrtc",
    "version": "1.0.0",
    "assetBundlePatterns": ["**/*"],
    "plugins": ["./plugin.js", "@config-plugins/react-native-webrtc"]
  }
}

内容的提问来源于stack exchange,提问作者Milan_Dignizant

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 20:40:34