react-native-community / upgrade-support

A central community-backed place to request and give help when upgrading your app.
MIT License
253 stars 2 forks source link

0.62 – dyld: Library not loaded: @rpath/libswiftCore.dylib #27

Open palkerecsenyi opened 4 years ago

palkerecsenyi commented 4 years ago

Environment

System:
    OS: macOS 10.15.4
    CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
    Memory: 851.91 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
    Yarn: Not Found
    npm: 6.14.4 - ~/.nvm/versions/node/v10.16.3/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.8.4 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.2
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 11.4/11E146 - /usr/bin/xcodebuild
  Languages:
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0 
    react-native: 0.62.0 => 0.62.0 
  npmGlobalPackages:
    *react-native*: Not Found

Upgrading version

0.61.5 -> 0.62.0 using https://react-native-community.github.io/upgrade-helper/?from=0.61.5&to=0.62.0 and #13. I have also set Always Embed Swift Standard Libraries to YES.

Description

The app builds successfully but crashes immediately (only on iOS) when opening. The following error is given:

0 __abort_with_payload
dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /Users/palkerecsenyi/Library/Developer/CoreSimulator/Devices/F8E756A1-8AA5-48DC-A91F-852E8CF898F5/data/Containers/Bundle/Application/29C37A01-AC12-4534-ACA6-3C7480F16992/PalChat.app/PalChat
  Reason: image not found
(lldb) 

Here are some of my project files:

AppDelegate.m

#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#if DEBUG
#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

#import <RNCPushNotificationIOS.h>
#import <TwitterKit/TWTRKit.h>
#import <UserNotifications/UserNotifications.h>

#import "RNNotifications.h"

@import Firebase;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#if DEBUG
  InitializeFlipper(application);
#endif
  [RNNotifications startMonitorNotifications];

  if ([FIRApp defaultApp] == nil) {
    [FIRApp configure];
  }

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"PalChat"
                                            initialProperties:nil];

  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
  return [[Twitter sharedInstance] application:app openURL:url options:options];
}

//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
  completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}

// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
  [RNCPushNotificationIOS didRegisterUserNotificationSettings:notificationSettings];
}
// 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 localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
  [RNCPushNotificationIOS didReceiveLocalNotification:notification];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [RNNotifications didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  [RNNotifications didFailToRegisterForRemoteNotificationsWithError:error];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end

AppDelegate.h

#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>

@property (nonatomic, strong) UIWindow *window;

@end

PalChat-Bridging-Header.h

#ifndef PalChat_Bridging_Header_h
#define PalChat_Bridging_Header_h

#endif /* PalChat_Bridging_Header_h */

Dummy.swift

import Foundation

Podfile

platform :ios, '10.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

def add_flipper_pods!
  version = '~> 0.33.1'
  pod 'FlipperKit', version, :configuration => 'Debug'
  pod 'FlipperKit/FlipperKitLayoutPlugin', version, :configuration => 'Debug'
  pod 'FlipperKit/SKIOSNetworkPlugin', version, :configuration => 'Debug'
  pod 'FlipperKit/FlipperKitUserDefaultsPlugin', version, :configuration => 'Debug'
  pod 'FlipperKit/FlipperKitReactPlugin', version, :configuration => 'Debug'
end
# Post Install processing for Flipper
def flipper_post_install(installer)
  installer.pods_project.targets.each do |target|
    if target.name == 'YogaKit'
      target.build_configurations.each do |config|
        config.build_settings['SWIFT_VERSION'] = '4.1'
      end
    end
  end
  file_name = Dir.glob("*.xcodeproj")[0]
  app_project = Xcodeproj::Project.open(file_name)
  app_project.native_targets.each do |target|
    target.build_configurations.each do |config|
      cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) '
      unless cflags.include? '-DFB_SONARKIT_ENABLED=1'
        puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...'
        cflags << '-DFB_SONARKIT_ENABLED=1'
      end
      config.build_settings['OTHER_CFLAGS'] = cflags
    end
    app_project.save
  end
  installer.pods_project.save
end

target 'PalChat' do
  # Pods for RnDiffApp
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/'
  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'ReactCommon/callinvoker', :path => "../node_modules/react-native/ReactCommon"
  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga', :modular_headers => true

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  permissions_path = '../node_modules/react-native-permissions/ios'

  pod 'Permission-Contacts', :path => "#{permissions_path}/Contacts.podspec"
  pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse.podspec"
  pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications.podspec"
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera.podspec"

  pod 'Firebase/Messaging', '~> 6.13.0'

  use_native_modules!

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.
  add_flipper_pods!
  post_install do |installer|
    flipper_post_install(installer)
  end
end

target 'PalChat-tvOS' do
  # Pods for RnDiffApp-tvOS

  target 'PalChat-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end
end

package.json

{
  "name": "PalChat",
  "version": "3.5.3",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "postinstall": "patch-package",
    "lint": "eslint ."
  },
  "dependencies": {
    "@invertase/react-native-apple-authentication": "^0.1.1",
    "@react-native-community/async-storage": "^1.6.2",
    "@react-native-community/blur": "https://github.com/react-native-community/react-native-blur.git#e2075520c709caf3bb8cf8890fcbf9f96939c716",
    "@react-native-community/cameraroll": "^1.2.1",
    "@react-native-community/datetimepicker": "^2.1.0",
    "@react-native-community/geolocation": "^1.4.2",
    "@react-native-community/google-signin": "^3.0.0",
    "@react-native-community/masked-view": "^0.1.6",
    "@react-native-community/picker": "^1.3.0",
    "@react-native-community/push-notification-ios": "^1.0.5",
    "@react-native-firebase/analytics": "^6.3.4",
    "@react-native-firebase/app": "^6.3.4",
    "@react-native-firebase/auth": "^6.3.4",
    "@react-native-firebase/crashlytics": "^6.3.4",
    "@react-native-firebase/dynamic-links": "^6.3.4",
    "@react-native-firebase/firestore": "^6.3.4",
    "@react-native-firebase/messaging": "^6.3.4",
    "@react-native-firebase/perf": "^6.3.4",
    "@react-native-firebase/remote-config": "^6.3.4",
    "@react-native-firebase/storage": "^6.3.4",
    "@react-navigation/bottom-tabs": "^5.2.4",
    "@react-navigation/native": "^5.1.3",
    "@react-navigation/stack": "^5.2.8",
    "@rnhooks/keyboard": "0.0.2",
    "algoliasearch": "^3.35.1",
    "fast-sort": "^1.5.6",
    "geofirestore": "^3.3.1",
    "immer": "^4.0.2",
    "jetifier": "^1.6.1",
    "jsc-android": "^241213.1.0",
    "libphonenumber-js": "^1.7.22",
    "lodash": "^4.17.15",
    "moment": "^2.24.0",
    "react": "16.11.0",
    "react-devtools": "^3.6.3",
    "react-firebase-hooks": "^2.1.1",
    "react-instantsearch": "^6.3.0",
    "react-instantsearch-dom": "^6.3.0",
    "react-instantsearch-native": "^6.3.0",
    "react-native": "0.62.0",
    "react-native-animate-number": "^0.1.2",
    "react-native-appstate-hook": "^1.0.1",
    "react-native-autogrow-textinput": "^5.2.0",
    "react-native-console-time-polyfill": "^1.2.1",
    "react-native-contacts": "^5.0.7",
    "react-native-country-picker-modal": "^0.8.0",
    "react-native-dark-mode": "^0.2.0",
    "react-native-device-info": "^2.3.2",
    "react-native-exception-handler": "^2.10.8",
    "react-native-fast-image": "^7.0.2",
    "react-native-flags": "^1.0.0",
    "react-native-fs": "^2.16.2",
    "react-native-geocoder": "^0.5.0",
    "react-native-gesture-handler": "^1.5.3",
    "react-native-image-gallery": "^2.1.5",
    "react-native-image-picker": "^2.3.0",
    "react-native-image-resizer": "^1.0.1",
    "react-native-image-viewing": "^0.1.8",
    "react-native-inappbrowser-reborn": "^2.0.4",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-maps": "^0.26.1",
    "react-native-modal": "^11.5.5",
    "react-native-modal-datetime-picker": "^8.5.1",
    "react-native-navigation-bar-color": "^0.1.0",
    "react-native-notifications": "^3.1.2",
    "react-native-open-maps": "^0.3.5",
    "react-native-paper": "^3.6.0",
    "react-native-permissions": "^2.0.8",
    "react-native-quick-actions": "^0.3.12",
    "react-native-reanimated": "^1.7.0",
    "react-native-safe-area": "^0.5.1",
    "react-native-safe-area-context": "^0.6.2",
    "react-native-screens": "^2.4.0",
    "react-native-select-multiple": "git+https://github.com/MnaveedS/react-native-select-multiple.git",
    "react-native-shimmer": "^0.5.0",
    "react-native-stars": "git+https://github.com/palkerecsenyi/react-native-stars.git",
    "react-native-swiper": "^1.6.0-rc.3",
    "react-native-twitter-signin": "^1.1.1",
    "react-native-vector-icons": "^6.6.0",
    "recyclerlistview": "^3.0.0",
    "rxjs": "^6.5.3",
    "use-dimensions": "^1.0.2",
    "use-immer": "^0.3.4"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "@types/lodash": "^4.14.149",
    "@types/react": "^16.9.0",
    "@types/react-native": "^0.62.0",
    "@types/react-native-vector-icons": "^6.4.5",
    "@welldone-software/why-did-you-render": "^4.0.5",
    "babel-jest": "^24.9.0",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "eslint": "^6.5.1",
    "hermes-engine": "^0.2.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.58.0",
    "patch-package": "^6.2.0",
    "react-test-renderer": "16.11.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

My Swift build settings: image image

I have tried:

but nothing has worked so far.

Reproducible demo

I was unable to recreate this error in a fresh React Native project, which leads me to believe that I did something wrong during the upgrade. The project worked perfectly on RN 0.61.5.

Thanks in advance, and please let me know if there are any other files/logs I need to provide.

palkerecsenyi commented 4 years ago

If anyone happens to have this (or a similar) issue, and you don't need Flipper support for your app, disabling Flipper solves the issue.

Comment out these lines from Podfile:

add_flipper_pods!
post_install do |installer|
  flipper_post_install(installer)
end

And from AppDelegate.m:

#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

// ...
#if DEBUG
  InitializeFlipper(application);
#endif

I know this fix isn't really a fix at all, but if you want the other new features/bug fixes in 0.62 and are okay without Flipper, you can disable it altogether on iOS fairly easily.

EmpireJones commented 4 years ago

I was getting that error, and this fixed it for me: https://github.com/react-native-community/upgrade-support/issues/30#issuecomment-608495255

I added a File.swift in my projects, and it was ok. But if I removed the file again, it crashed again. So, in xCode, I went to BuildSettings -> Linking -> runpath search path , and manually changed each build line to:

/usr/lib/swift $(inherited) And now it builds and starts fine, without the .swift file

nataliepan commented 3 years ago

Took me hours to figure this out but I had to manually add Flipper to my Podfile, since I could not run react-native update on my project. I noticed I wasn't getting all these extra Flipper pod files compared to a new project. https://fbflipper.com/docs/getting-started/react-native-ios

platform :ios, '9.0'

def flipper_pods()
  flipperkit_version = '0.49.0'
  pod 'FlipperKit', '~>' + flipperkit_version, :configuration => 'Debug'
  pod 'FlipperKit/FlipperKitLayoutPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
  pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
  pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
  pod 'FlipperKit/FlipperKitReactPlugin', '~>' + flipperkit_version, :configuration => 'Debug'
end

# Post Install processing for Flipper
def flipper_post_install(installer)
  file_name = Dir.glob("*.xcodeproj")[0]
  app_project = Xcodeproj::Project.open(file_name)
  app_project.native_targets.each do |target|
    target.build_configurations.each do |config|
      cflags = config.build_settings['OTHER_CFLAGS'] || '$(inherited) '
      unless cflags.include? '-DFB_SONARKIT_ENABLED=1'
        puts 'Adding -DFB_SONARKIT_ENABLED=1 in OTHER_CFLAGS...'
        cflags << '-DFB_SONARKIT_ENABLED=1'
      end
      config.build_settings['OTHER_CFLAGS'] = cflags
    end
    app_project.save
  end
  installer.pods_project.save
end

target 'your-app-name' do
  ...

  # Replace the existing yoga import with the following (adding modular_headers):
  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga', :modular_headers => true

  ...
  use_native_modules!

  # For enabling Flipper.
  # Note that if you use_framework!, flipper will not work.
  # Disable these lines if you are doing use_framework!
  flipper_pods()
  post_install do |installer|
    flipper_post_install(installer)
  end
end
yj-ang commented 3 years ago

Add @executable_path/Frameworks at Runpath Search Paths worked for me.

https://stackoverflow.com/a/57669947/6162478

gndelia commented 3 years ago

I had the same issue here, I tried tons of solutions in Stack Overflow (such as the one linked above this comment ☝🏽 ) but the only thing that managed to remove this error was disabling flipper 😞

hbarylskyi commented 2 years ago

Had the same issue and only adding /usr/lib/swift to Runpath Search Paths helped.

https://stackoverflow.com/a/69852407/4896751