Expo独立iOS项目中如何启用use_modular_headers!?
在Expo独立项目中配置iOS Podfile的modular headers以适配@baronha/react-native-photo-editor
在Expo独立项目里,手动修改Podfile没用——eas build会自动重置配置,必须用Config Plugins来持久化修改Podfile的modular headers设置,下面给两种可行方案:
方案1:全局启用use_modular_headers!
如果项目里没有其他库会和全局modular headers冲突,直接给所有Pod开启模块化头文件:
- 在项目根目录创建一个Config Plugin文件,比如
withPhotoEditorPodConfig.js:
const { withPodfileProperties } = require('@expo/config-plugins'); module.exports = function withPhotoEditorPodConfig(config) { return withPodfileProperties(config, (props) => { // 全局启用modular headers props.modResults.use_modular_headers = true; return props; }); };
- 在
app.json或app.config.js里注册这个插件:
{ "expo": { "plugins": ["./withPhotoEditorPodConfig.js"] } }
方案2:只为特定依赖启用modular headers(推荐)
全局开启可能影响其他第三方库的兼容性,更稳妥的方式是只给需要的依赖(SDWebImage、SDWebImageWebPCoder)单独设置:
- 创建Config Plugin文件
withPhotoEditorPodConfig.js:
const { withPodfile } = require('@expo/config-plugins'); module.exports = function withPhotoEditorPodConfig(config) { return withPodfile(config, (props) => { let podfileContent = props.modResults.contents; // 给SDWebImage添加modular headers配置 podfileContent = podfileContent.replace( /pod 'SDWebImage',.*?/, "pod 'SDWebImage', :modular_headers => true" ); // 给SDWebImageWebPCoder添加modular headers配置 podfileContent = podfileContent.replace( /pod 'SDWebImageWebPCoder',.*?/, "pod 'SDWebImageWebPCoder', :modular_headers => true" ); props.modResults.contents = podfileContent; return props; }); };
- 同样在
app.json/app.config.js里注册插件,然后运行eas build -p ios重新构建iOS项目即可。
注意事项
- 如果你的项目是用
expo prebuild生成过原生代码的独立项目,也可以直接修改ios/Podfile,但每次expo prebuild都会覆盖,所以还是推荐用Config Plugins做持久化配置。 - 本地调试前记得清理缓存:
rm -rf ios/Pods ios/Podfile.lock && pod install。
内容的提问来源于stack exchange,提问作者error code
相关产品推荐
相关产品推荐

