React-native: Build failed with error '_swift_getTypeByMangledNameInContextInMetadataState' when adding Notification Content Extension to iOS project.

Created on 29 Jun 2020  路  10Comments  路  Source: facebook/react-native

Description

Build failed with an error when adding Notification Content Extension to iOS project.

Undefined symbols for architecture arm64:
  "_swift_getTypeByMangledNameInContextInMetadataState", referenced from:
      ___swift_instantiateConcreteTypeFromMangledNameAbstract in NotificationViewController.o

React Native version:


react-native info result

System:
    OS: macOS 10.16
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 107.45 MB / 16.00 GB
    Shell: 2.7.1 - /usr/local/bin/fish
  Binaries:
    Node: 10.16.0 - ~/.nvm/versions/node/v10.16.0/bin/node
    Yarn: 1.22.4 - ~/.yarn/bin/yarn
    npm: 6.10.3 - ~/.nvm/versions/node/v10.16.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 23, 28, 29
      Build Tools: 28.0.3, 29.0.2
      System Images: android-25 | Google APIs ARM EABI v7a, android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  npmPackages:
    @react-native-community/cli: 4.9.0 => 4.9.0 
    react: ^16.13.1 => 16.13.1 
    react-native: 0.62.2 => 0.62.2 
  npmGlobalPackages:
    create-react-native-module: 0.16.0

Steps To Reproduce

  1. in Xcode, select File -> New -> Target and choose Notification Content Extension.
  2. Build project and error occurs.

Expected Results

Add Notification Content Extension to React Native project and build it successfully.

Needs iOS

Most helpful comment

I use the following method to solve the problem

LIBRARY_SEARCH_PATHS = (
   "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
-  "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
+  "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.2/$(PLATFORM_NAME)\"",
   "\"$(inherited)\"",
 );

All 10 comments

Same here, but when trying to implement Apollo for Graphql as a swift package

Undefined symbols for architecture x86_64:
  "_swift_getTypeByMangledNameInContextInMetadataState", referenced from:
      ___swift_instantiateConcreteTypeFromMangledNameAbstract in ShareViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

how to resolve?

I use the following method to solve the problem

LIBRARY_SEARCH_PATHS = (
   "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"",
-  "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
+  "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.2/$(PLATFORM_NAME)\"",
   "\"$(inherited)\"",
 );

@hengkx cool, now it builds 馃槂

I also had this issue and asked about it on the Swift forums. The cause is trying to link against an older Swift runtime while targeting a newer version of the OS.

You should be able to just remove those LIBRARY_SEARCH_PATH entries entirely (or just leave $(inherited)) and that will fix the problem. This is a bug in the ReactNative template for iOS.

As mentioned in the above Swift forums thread:

You shouldn't need to add the toolchain library paths to LIBRARY_SEARCH_PATHS yourself, because Xcode will automatically include those libraries if your minimum deployment target is old enough to need them.

@hengkx, it works for me! Thanks a lot!

Sorry for commenting on a closed issue, but I'm still experiencing this problem and nothing seems to help. I've tried changing my IPHONEOS_DEPLOYMENT_TARGET to 9.0, 10.0, 11.0 and 13.5, nothing works. I've tried @hengkx 's fix, didn't work. I've tried leaving only inherited in there, and removing it entirely, still didn't work. Can anyone help me out here?

Screenshot 2020-09-17 at 13 35 43

EDIT: Fixed it! My notification service extension had a different deployment target version than the RN app.

Same issue here, adding a WidgetExtension to a blank react-native app causes this issue. None of the above fixes seem to work

I also had this issue and asked about it on the Swift forums. The cause is trying to link against an older Swift runtime while targeting a newer version of the OS.

You should be able to just remove those LIBRARY_SEARCH_PATH entries entirely (or just leave $(inherited)) and that will fix the problem. This is a bug in the ReactNative template for iOS.

As mentioned in the above Swift forums thread:

You shouldn't need to add the toolchain library paths to LIBRARY_SEARCH_PATHS yourself, because Xcode will automatically include those libraries if your minimum deployment target is old enough to need them.

馃憜 This is the real fix

Was this page helpful?
0 / 5 - 0 ratings