用expo更新react原生库是多么彻底的噩梦。我尝试更新代码库,以帮助我的应用程序变得最新。然而,正如预期的那样,它不像运行npm update --force
:D那么容易。过去几天我一直在经历错误;今天是修复错误的第三天,直到我成功构建。今天的错误真的困扰着我。现在有人如何解决以下问题吗?:
错误
The Swift pod `ExpoModulesCore` depends upon `React-RCTAppDelegate`, which does not define modules.
我尝试将pod'ExpoModulesCore',:modular_headers => true
添加到我的pod文件中,但这导致了以下错误:
[!] Unable to find a specification for `ExpoModulesCore`
…尽管我的package.json文件中有这个,我将在下面添加。package.json中的名称不同,它在单词之间有炒作。但是,如果我将名称更改为该名称,则仅使用相应的名称就会出现相同的错误。
所以我尝试了一个全局modular_headers,但随后出现了一个名空间冲突和google错误。然后我尝试添加pod 'React-RCTAppDelegate', :modular_headers => true
,但出现以下错误
[!] There are multiple dependencies with different sources for `React-RCTAppDelegate` in `Podfile`: - React-RCTAppDelegate - React-RCTAppDelegate (from `../node_modules/react-native/Libraries/AppDelegate`)
我完全不知道该怎么做了,这肯定是错误49/xxx。我将提供我的旧包.json和新包以及podfile和delegate.m和h文件。感谢任何帮助。
我降级了expo,因为它帮助我解决了另一个我遇到的错误,该错误与reatredelegate中未定义的模块有关
新包.json
{ "scripts": { "start": "react-native start", "android": "react-native run-android", "ios": "react-native run-ios", "web": "expo start --web", "eject": "expo eject", "build:ios": "react-native bundle — entry-file index.js — platform ios — dev false — bundle-output ios/main.jsbundle — assets-dest ios" }, "dependencies": { "@expo/vector-icons": "^13.0.0", "@gregfrench/react-native-wheel-picker": "^1.2.16", "@react-native-community/datetimepicker": "^6.7.3", "@react-native-community/masked-view": "0.1.10", "@react-native-community/push-notification-ios": "^1.10.1", "@react-native-firebase/app": "^17.0.0", "@react-native-firebase/messaging": "^17.0.0", "@react-native-picker/picker": "^2.4.8", "@reduxjs/toolkit": "^1.9.2", "@sentry/react-native": "^4.14.0", "axios": "^1.3.2", "buffer": "^6.0.3", "expo": "47.0.9", "expo-barcode-scanner": "~12.1.0", "expo-camera": "~13.1.0", "expo-device": "^5.0.0", "expo-image-manipulator": "~11.0.0", "expo-image-picker": "~14.1.0", "expo-media-library": "~15.0.0", "expo-modules-core": "1.1.1", "expo-notifications": "^0.17.0", "expo-permissions": "~14.0.0", "expo-secure-store": "~12.0.0", "expo-splash-screen": "^0.17.5", "expo-sqlite": "~11.0.0", "expo-status-bar": "~1.4.2", "expo-updates": "^0.15.6", "formik": "^2.2.9", "lodash": "^4.17.21", "moment": "^2.29.4", "react": "18.2.0", "react-axios": "^2.0.6", "react-dom": "18.2.0", "react-native": "^0.71.2", "react-native-appearance": "^0.3.4", "react-native-background-actions": "^3.0.0", "react-native-background-fetch": "^4.1.8", "react-native-ble-plx": "^2.0.3", "react-native-calendars": "^1.1293.0", "react-native-device-info": "^10.3.0", "react-native-elements": "^3.4.3", "react-native-fast-image": "^8.6.3", "react-native-gesture-handler": "~2.9.0", "react-native-image-slider-box": "^2.0.7", "react-native-image-zoom-viewer": "^3.0.1", "react-native-keyboard-aware-scrollview": "^2.1.0", "react-native-permissions": "^3.6.1", "react-native-push-notification": "^8.1.1", "react-native-reanimated": "^2.14.4", "react-native-safe-area-context": "4.5.0", "react-native-screens": "~3.19.0", "react-native-snap-carousel": "^3.9.1", "react-native-switch": "^2.0.0", "react-native-unimodules": "^0.14.10", "react-native-web": "^0.18.12", "react-native-webview": "^11.26.1", "react-native-wheel-picker-android": "^2.0.6", "react-navigation": "^4.4.3", "react-navigation-stack": "^2.9.0", "react-redux": "^8.0.5", "rn-fetch-blob": "^0.12.0", "toggle-switch-react-native": "^3.3.0" }, "devDependencies": { "@babel/core": "~7.20.12", "babel-jest": "~29.4.1", "jest": "^29.4.1", "prettier": "^2.8.3", "react-test-renderer": "~18.2.0", "typescript": "~4.9.5" }, "private": true, "name": "pdi-app-v2", "version": "1.0.0" }
旧包.json
{ "scripts": { "start": "react-native start", "android": "react-native run-android", "ios": "react-native run-ios", "web": "expo start --web", "eject": "expo eject", "build:ios": "react-native bundle — entry-file index.js — platform ios — dev false — bundle-output ios/main.jsbundle — assets-dest ios" }, "dependencies": { "@expo/vector-icons": "^10.0.0", "@gregfrench/react-native-wheel-picker": "^1.2.14", "@react-native-community/datetimepicker": "^3.0.9", "@react-native-community/masked-view": "0.1.10", "@react-native-community/push-notification-ios": "^1.7.1", "@react-native-firebase/app": "^8.4.7", "@react-native-firebase/messaging": "^7.9.1", "@react-native-picker/picker": "^1.16.1", "@reduxjs/toolkit": "^1.4.0", "@sentry/react-native": "^3.2.10", "axios": "^0.15.0", "buffer": "^6.0.2", "expo": "~39.0.2", "expo-barcode-scanner": "~9.0.0", "expo-camera": "~9.0.0", "expo-device": "~2.3.0", "expo-image-manipulator": "~8.3.0", "expo-image-picker": "~9.1.1", "expo-media-library": "~9.2.1", "expo-notifications": "0.8.2", "expo-permissions": "~9.3.0", "expo-secure-store": "~9.2.0", "expo-splash-screen": "~0.6.1", "expo-sqlite": "~8.4.0", "expo-status-bar": "~1.0.2", "expo-updates": "~0.3.3", "formik": "^2.2.9", "lodash": "^4.17.21", "moment": "^2.29.0", "react": "16.13.1", "react-axios": "2.0.3", "react-dom": "16.13.1", "react-native": "0.63.4", "react-native-appearance": "^0.3.4", "react-native-background-actions": "^2.6.1", "react-native-background-fetch": "^4.0.2", "react-native-ble-plx": "^2.0.3", "react-native-calendars": "^1.403.0", "react-native-device-info": "^8.1.3", "react-native-elements": "^2.3.2", "react-native-fast-image": "^8.3.4", "react-native-gesture-handler": "~1.7.0", "react-native-image-slider-box": "^1.0.12", "react-native-image-zoom-viewer": "^3.0.1", "react-native-keyboard-aware-scrollview": "^2.1.0", "react-native-permissions": "^3.0.5", "react-native-push-notification": "^6.1.3", "react-native-reanimated": "~1.13.0", "react-native-safe-area-context": "3.1.4", "react-native-screens": "~2.10.1", "react-native-snap-carousel": "^3.9.1", "react-native-switch": "^2.0.0", "react-native-unimodules": "~0.11.0", "react-native-web": "0.14.0", "react-native-webview": "^10.8.2", "react-native-wheel-picker-android": "^2.0.6", "react-navigation": "^4.4.3", "react-navigation-stack": "^2.9.0", "react-redux": "^7.2.2", "rn-fetch-blob": "^0.12.0", "toggle-switch-react-native": "^2.3.0" }, "devDependencies": { "@babel/core": "~7.9.0", "babel-jest": "~25.2.6", "jest": "~25.2.6", "prettier": "^2.5.1", "react-test-renderer": "~16.13.1", "typescript": "~3.9.2" }, "private": true, "name": "pdi-app-v2", "version": "1.0.0" }
#播客文件
require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking") require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods") require File.join(File.dirname(`node --print "require.resolve('@react-native-community/cli-platform-ios/package.json')"`), "native_modules") pod 'Firebase', :modular_headers => true pod 'FirebaseCore', :modular_headers => true pod 'GoogleUtilities', :modular_headers => true pod 'React-RCTAppDelegate', :modular_headers => true $RNFirebaseAsStaticFramework = true require 'json' podfile_properties = JSON.parse(File.read(File.join(__dir__, 'Podfile.properties.json'))) rescue {} platform :ios, podfile_properties['ios.deploymentTarget'] || '13.0' install! 'cocoapods', :deterministic_uuids => false target 'pdimobile' do use_expo_modules! config = use_native_modules! use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks'] # Flags change depending on the env values. flags = get_default_flags() use_flipper! # should match the version of your Flipper client app use_react_native!( :path => config[:reactNativePath], :hermes_enabled => podfile_properties['expo.jsEngine'] == 'hermes', :fabric_enabled => flags[:fabric_enabled], # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/..", ) post_install do |installer| flipper_post_install(installer) react_native_post_install( installer, # Set `mac_catalyst_enabled` to `true` in order to apply patches # necessary for Mac Catalyst builds :mac_catalyst_enabled => false ) __apply_Xcode_12_5_M1_post_install_workaround(installer) # This is necessary for Xcode 14, because it signs resource bundles by default # when building for devices. installer.target_installation_results.pod_target_installation_results .each do |pod_name, target_installation_result| target_installation_result.resource_bundle_targets.each do |resource_bundle_target| resource_bundle_target.build_configurations.each do |config| config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' end end end end permissions_path = '../node_modules/react-native-permissions/ios' pod 'Permission-BluetoothPeripheral', :path => "#{permissions_path}/BluetoothPeripheral" pod 'Permission-Camera', :path => "#{permissions_path}/Camera" pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications" pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary" post_integrate do |installer| begin expo_patch_react_imports!(installer) rescue => e Pod::UI.warn e end begin expo_patch_react_imports!(installer) rescue => e Pod::UI.warn e end end end
#应用委托.h
#import <UserNotifications/UNUserNotificationCenter.h> #import <Expo/Expo.h> #import <Foundation/Foundation.h> #import <EXUpdates/EXUpdatesAppController.h> #import <React/RCTBridgeDelegate.h> #import <UIKit/UIKit.h> #import <UMCore/UMAppDelegateWrapper.h> @interface AppDelegate : UMAppDelegateWrapper <RCTBridgeDelegate, EXUpdatesAppControllerDelegate, UNUserNotificationCenterDelegate> @end
应用委托.m
#import <Firebase.h> #import "AppDelegate.h" #import <UserNotifications/UserNotifications.h> #import <RNCPushNotificationIOS.h> #import <React/RCTBridge.h> #import <React/RCTBundleURLProvider.h> #import <React/RCTRootView.h> #import <TSBackgroundFetch/TSBackgroundFetch.h> #if RCT_DEV #import <React/RCTDevLoadingView.h> #endif #import <UMCore/UMModuleRegistry.h> #import <UMReactNativeAdapter/UMNativeModulesProxy.h> #import <UMReactNativeAdapter/UMModuleRegistryAdapter.h> #import <EXSplashScreen/EXSplashScreenService.h> #import <UMCore/UMModuleRegistryProvider.h> #ifdef FB_SONARKIT_ENABLED #import <FlipperKit/FlipperClient.h> #import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h> #import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h> #import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h> #import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h> #import <FlipperKitReactPlugin/FlipperKitReactPlugin.h> static void InitializeFlipper(UIApplication *application) { FlipperClient *client = [FlipperClient sharedClient]; SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults]; [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]]; [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]]; [client addPlugin:[FlipperKitReactPlugin new]]; [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]]; [client start]; } #endif @interface AppDelegate () <RCTBridgeDelegate> @property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter; @property (nonatomic, strong) NSDictionary *launchOptions; @end @implementation AppDelegate // Required for the register event. - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the notification event. You must call the completion handler after handling the remote notification. - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler]; } // Required for the registrationError event. - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error]; } // Required for localNotification event - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler { [RNCPushNotificationIOS didReceiveNotificationResponse:response]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { #ifdef FB_SONARKIT_ENABLED InitializeFlipper(application); #endif self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]]; self.launchOptions = launchOptions; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; #ifdef DEBUG [self initializeReactNativeApp]; #else EXUpdatesAppController *controller = [EXUpdatesAppController sharedInstance]; controller.delegate = self; [controller startAndShowLaunchScreen:self.window]; #endif [super application:application didFinishLaunchingWithOptions:launchOptions]; if([FIRApp defaultApp] == nil) { [FIRApp configure]; } NSURL *jsCodeLocation; jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation moduleProvider:nil launchOptions:launchOptions]; #if RCT_DEV [bridge moduleForClass:[RCTDevLoadingView class]]; #endif RCTRootView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"Test" initialProperties:nil]; UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [[TSBackgroundFetch sharedInstance] didFinishLaunching]; return YES; } //Called when a notification is delivered to a foreground app. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { if (@available(iOS 14.0, *)) { completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionBanner | UNNotificationPresentationOptionBadge); } else { // Fallback on earlier versions completionHandler(UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert | UNNotificationPresentationOptionBadge); } } - (RCTBridge *)initializeReactNativeApp { RCTBridge *bridge = [self.reactDelegate createBridgeWithDelegate:self launchOptions:self.launchOptions]; RCTRootView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"main" initialProperties:nil]; rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; UIViewController *rootViewController = [self.reactDelegate createRootViewController]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; return bridge; } - (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge { NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge]; // If you'd like to export some custom RCTBridgeModules that are not Expo modules, add them here! return extraModules; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #ifdef DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[EXUpdatesAppController sharedInstance] launchAssetUrl]; #endif } - (void)appController:(EXUpdatesAppController *)appController didStartWithSuccess:(BOOL)success { appController.bridge = [self initializeReactNativeApp]; EXSplashScreenService *splashScreenService = (EXSplashScreenService *)[UMModuleRegistryProvider getSingletonModuleForClass:[EXSplashScreenService class]]; [splashScreenService showSplashScreenFor:self.window.rootViewController]; } @end