最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Expo Prebuild for React Native ios - Stack Overflow

programmeradmin1浏览0评论

I've noticed a behavior when running expo prebuild in my React Native project using Expo. For the iOS platform, it completely replaces the AppDelegate.mm file and regenerates new icons. However, on Android, I don’t see as many changes.

The issue I'm facing is that whenever I modify AppDelegate.mm (e.g., for setting up a native module) and then run expo prebuild again, all my changes are lost.

Is this the expected behavior? If so, what’s the recommended approach to persist changes in AppDelegate.mm while using Expo prebuild? Also, why doesn’t Android seem to have as many changes compared to iOS?

Would appreciate any insights on this. Thanks!

I've noticed a behavior when running expo prebuild in my React Native project using Expo. For the iOS platform, it completely replaces the AppDelegate.mm file and regenerates new icons. However, on Android, I don’t see as many changes.

The issue I'm facing is that whenever I modify AppDelegate.mm (e.g., for setting up a native module) and then run expo prebuild again, all my changes are lost.

Is this the expected behavior? If so, what’s the recommended approach to persist changes in AppDelegate.mm while using Expo prebuild? Also, why doesn’t Android seem to have as many changes compared to iOS?

Would appreciate any insights on this. Thanks!

Share Improve this question edited 6 hours ago Samarth Kadam asked yesterday Samarth KadamSamarth Kadam 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Create a custom Expo config plugin (plugin.js) This ensures that your modifications are applied every time expo prebuild runs.

const { withDangerousMod } = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');
        
module.exports = function withCustomAppDelegate(config) {
          return withDangerousMod(config, ['ios', (config) => {
            const appDelegatePath = path.join(config.modRequest.platformProjectRoot, 'MyApp', 'AppDelegate.mm');
        
        let content = fs.readFileSync(appDelegatePath, 'utf-8');
        
        // Example: Add a custom import or native module setup
        if (!content.includes('#import "MyNativeModule.h"')) {
          content = content.replace(
            '#import <React/RCTBridgeModule.h>',
            `#import <React/RCTBridgeModule.h>\n#import "MyNativeModule.h"`
          );
        }
    
        fs.writeFileSync(appDelegatePath, content);
        return config;
      }]);
    };
发布评论

评论列表(0)

  1. 暂无评论