React Native Android新增Stage构建类型启动崩溃问题求助
问题描述
我正尝试为React Native安卓应用新增Stage构建类型,现有Debug和Release变体运行正常,但新变体关联存在问题。Stage构建可顺利完成,但应用启动时崩溃,无法加载Metro,报错如下:
2022-08-30 19:56:07.883 8232-8232/com.ourapp.stage E/SoLoader: couldn't find DSO to load: libjscexecutor.so
另外,新增的Stage仅应用于主App模块,未覆盖其他模块(不确定是否为问题线索)。当前构建配置代码如下:
buildTypes { debug { applicationIdSuffix ".myapp" signingConfig signingConfigs.debug minifyEnabled false proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" matchingFallbacks = ['debug', 'release'] if (nativeArchitectures) { ndk { abiFilters nativeArchitectures.split(',') } } } stage { initWith debug applicationIdSuffix ".myapp.stage" } release { // Caution! In production, you need to generate your own keystore file. // see https://reactnative.dev/docs/signed-apk-android. signingConfig signingConfigs.release minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" applicationIdSuffix ".myapp.prod" debuggable false }
解决方案
添加构建类型回退策略
第三方依赖模块通常没有定义Stage构建类型,Gradle无法匹配到对应变体,导致SO文件缺失。给Stage配置matchingFallbacks:stage { initWith debug applicationIdSuffix ".myapp.stage" matchingFallbacks = ['debug'] // 指定回退到Debug变体 }同步NDK架构配置
尽管Stage继承自Debug,但动态变量nativeArchitectures可能未被正确继承,显式配置NDK abiFilters确保SO文件架构匹配:stage { initWith debug applicationIdSuffix ".myapp.stage" matchingFallbacks = ['debug'] if (nativeArchitectures) { ndk { abiFilters nativeArchitectures.split(',') } } }统一所有模块的构建类型
仅主App模块有Stage变体,依赖模块仍用Debug,会导致SO文件未被打包进Stage构建。在项目根目录的settings.gradle中添加配置,让所有模块生成Stage构建类型:subprojects { afterEvaluate { project -> if (project.plugins.hasPlugin('com.android.library')) { project.android.buildTypes.create('stage') { initWith project.android.buildTypes.debug } } } }清理缓存重新构建
执行命令清理旧构建文件,避免缓存干扰:./gradlew clean ./gradlew assembleStage
内容的提问来源于stack exchange,提问作者Fapi
相关产品推荐
相关产品推荐

