Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined symbol: _OBJC_CLASS_$_RCTImageLoader #842

Closed
khasbilegt opened this issue Mar 4, 2021 · 30 comments · Fixed by #934
Closed

Undefined symbol: _OBJC_CLASS_$_RCTImageLoader #842

khasbilegt opened this issue Mar 4, 2021 · 30 comments · Fixed by #934

Comments

@khasbilegt
Copy link

Description

Build fails on react-native-screens versions 2.18.0, 2.18.1 but works fine on previous versions.

Screenshots

image

Steps To Reproduce

  1. yarn upgrade react-native-screens@latest
  2. yarn pod
  3. xcode build

Expected behavior

Successful Xcode build

Actual behavior

Failed Xcode build

Package versions

  • React: v16.13.1
  • React Native: v0.63.4
  • React Native Screens: v2.18.1
@WoLewicki
Copy link
Member

Can you reproduce this issue on the fresh react-native project? If no, it can be an issue of wrong transition between the react-native versions in your project. cc @jakmak24 since you had same problem.

@jakmak24
Copy link
Contributor

jakmak24 commented Mar 4, 2021

@khasbilegt Hi. I've experienced a similar issue and it was related to using use_frameworks! in Podfile.
Try adding the following step to your Podfile:

  pre_install do |installer|
    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNScreens')
        def pod.build_type
          Pod::BuildType.static_library
        end
      end
    end
  end

@kesha-antonov
Copy link

pre_install do |installer|
installer.pod_targets.each do |pod|
if pod.name.eql?('RNScreens')
def pod.build_type
Pod::BuildType.static_library
end
end
end
end

thanks, it helped!

@shariqsami
Copy link

@jakmak24 its causing this error

ld: warning: directory not found for option '-L-L/Users/apple/apps/appElection/ios/Build/Products/Debug-iphonesimulator/RNScreens'
ld: library not found for -lRNScreens
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@phuchungnguyen78
Copy link

phuchungnguyen78 commented Mar 16, 2021

I got the same issue with @khasbilegt , try to add some codes as jakmak24's suggestion, but it doesn't work.
I created react native project with salesforce mobile SDK (https://developer.salesforce.com/docs/atlas.en-us.mobile_sdk.meta/mobile_sdk/react_native_new_project.htm)

@d4niells
Copy link

d4niells commented Mar 16, 2021

Does anyone know how to explain why this happens? I'm doing the integration of react native with the existing ios app and I'm having this same problem in the x86_64 architecture not only in lib react-native-screens but also in react-native-masked-view and react-native-svg

xcode: 12.4v
react-native: 0.63.4v

@gmapnl
Copy link

gmapnl commented Mar 17, 2021

Exactly same issue, pre_install not helps

tried to add s.static_framework = true in RNScreens.podspec instead, without success.

Xcode : 12.4
React: v17.0.1
React Native: v0.64.0
React Native Screens: v2.18.1

@sujith-surendranath
Copy link

@phuchungnguyen78 did you find any solution for salesforce SDK + RN projects?

@WoLewicki
Copy link
Member

If the change suggested by @jakmak24 doesn't work for you, you can always revert the commit that introduces this change: #768 with e.g. patch-package.

@Jalil-Irfan
Copy link

@khasbilegt Hi. I've experienced a similar issue and it was related to using use_frameworks! in Podfile.
Try adding the following step to your Podfile:

  pre_install do |installer|
    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNScreens')
        def pod.build_type
          Pod::BuildType.static_library
        end
      end
    end
  end

Thanks it helped me by pass the issue but I would like to know the actual fix and also I would like to know what issues i can expect in future because of this pod file change

@sunzhongliangde
Copy link
Contributor

Sorry, I don't have this problem. Is there anyone else? Is there any problem using this version in a new project?

@flash76
Copy link

flash76 commented Mar 28, 2021

Sorry, I don't have this problem. Is there anyone else? Is there any problem using this version in a new project?

@sunzhongliangde I'm using it in my project, and adding the pre install action to build RNScreens as a static library causes
Cycle inside FBReactNativeSpec; building could produce unreliable results. This usually can be resolved by moving the shell script phase '[CP-User] Generate Specs' so that it runs before the build phase that depends on its outputs.

@gmapnl
Copy link

gmapnl commented Apr 2, 2021

Sorry, I don't have this problem. Is there anyone else? Is there any problem using this version in a new project?

@sunzhongliangde I'm using it in my project, and adding the pre install action to build RNScreens as a static library causes
Cycle inside FBReactNativeSpec; building could produce unreliable results. This usually can be resolved by moving the shell script phase '[CP-User] Generate Specs' so that it runs before the build phase that depends on its outputs.

It's another problem. Fixed for me with :

post_install do |installer|
  react_native_post_install(installer)
  
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
    end
    
    if (target.name&.eql?('FBReactNativeSpec'))
      target.build_phases.each do |build_phase|
        if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
          target.build_phases.move(build_phase, 0)
        end
      end
    end
  end
end

@WoLewicki
Copy link
Member

I will close this issue since it is not react-native-screens specific and the solutions are already listed. Please comment here if something is wrong and we can reopen it then.

@flash76
Copy link

flash76 commented Apr 11, 2021

@khasbilegt Hi. I've experienced a similar issue and it was related to using use_frameworks! in Podfile.
Try adding the following step to your Podfile:

  pre_install do |installer|
    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNScreens')
        def pod.build_type
          Pod::BuildType.static_library
        end
      end
    end
  end

I was also having this issue and I think I was able to fix it a bit more elegantly. Instead of doing use_frameworks! and putting pre-install directives, I used CocoaPods User-Defined Build Types and added :build_type => :dynamic_framework to the dependencies that required use_frameworks!.

@billnbell
Copy link

Sorry, I don't have this problem. Is there anyone else? Is there any problem using this version in a new project?

@sunzhongliangde I'm using it in my project, and adding the pre install action to build RNScreens as a static library causes
Cycle inside FBReactNativeSpec; building could produce unreliable results. This usually can be resolved by moving the shell script phase '[CP-User] Generate Specs' so that it runs before the build phase that depends on its outputs.

It's another problem. Fixed for me with :

post_install do |installer|
  react_native_post_install(installer)
  
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
    end
    
    if (target.name&.eql?('FBReactNativeSpec'))
      target.build_phases.each do |build_phase|
        if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
          target.build_phases.move(build_phase, 0)
        end
      end
    end
  end
end

I am using

target 'TheClub' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => true
  )

  target 'TheClubTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable these next few lines.

  if !ENV['CI']
    use_flipper!({ 'Flipper' => '0.79.1' })

    post_install do |installer|
      flipper_post_install(installer)
      installer.pods_project.targets.each do |t|
        t.build_configurations.each do |config|
          config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
        end
      end
    end
  end
end

How do I fix it?

@louishwh
Copy link

post_install do |installer|

react_native_post_install(installer)

installer.pod_targets.each do |pod|
  if pod.name.eql?('RNScreens')
    def pod.build_type
      Pod::BuildType.static_library
    end
  end

  if pod.name.eql?('RNCMaskedView')
    def pod.build_type
      Pod::BuildType.static_library
    end
  end
end

installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
        config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
    end
    
    if (target.name&.eql?('FBReactNativeSpec'))
         target.build_phases.each do |build_phase|
        if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
            target.build_phases.move(build_phase, 0)
        end
      end
    end
end

end

@markwilcox
Copy link
Contributor

I've just run into this issue today after upgrading react-native-screens. I'm working on a complex hybrid native/react-native app with use_frameworks!. I've seen similar issues on other React Native modules with native code too. It's a question of build timing luck, because RNScreens.podspec has a missing dependency. Adding a new pod, or updating a pod can cause this to start failing, or be magically fixed again. The RNScreens pod is trying to be linked before the React-RCTImage pod has been compiled, hence the missing symbol at link time.

When everyone shifted from depending on 'React' to 'React-Core' because Xcode got fussy about that, some packages that depend on bits of React Native outside 'React-Core' have not added all those frameworks explicitly.

Form me adding:
s.dependency "React-RCTImage"
to RNScreens.podspec fixes this issue. Although it would be worth double-checking what classes from React Native are actually used and which modules they're in to make sure all the dependencies are captured, because otherwise it's just luck what gets built in what order in each project.

I hope that all makes sense and it would be great if this could be fixed in a future release @WoLewicki 🙏 - then I can remove my package patch.

@WoLewicki
Copy link
Member

@markwilcox so could you make a PR with such a change and link it here for people to be able to test it and say if it resolves their issue? It would be great if we could resolve this issue by it.

@markwilcox
Copy link
Contributor

markwilcox commented May 12, 2021

I double checked the dependencies and it was only "React-RCTImage" that was missing. This gets our build through CI without any of the messy local podfile hacks suggested above. Made a PR - linked above. It shouldn't have any effect on users that don't have the error, you're just declaring your dependency on something that would get built anyway to ensure the correct build order.

@LPitonakova
Copy link

I've applied the suggested dependency "React-RCTImage" fix but keep getting the same error. Is there anything else you did, @markwilcox ? Did you also apply the pre-install instructions from above and if so, where exactly?

@markwilcox
Copy link
Contributor

No pre-install hacks required @LPitonakova but you do need to pod install again after applying the fix.

You can check the dependency has been correctly added in your Pods project in Xcode afterwards.

@LPitonakova
Copy link

@markwilcox I did pod install, then cleaned and re-built the project as well. Still the same error. I feel like I'm missing something! When you say "You can check the dependency has been correctly added in your Pods project in Xcode afterwards." - how exactly would I do that please?

@markwilcox
Copy link
Contributor

I’m on a phone, or I’d send you a screenshot. There should be a project called Pods in your Xcode Workspace. Inside that there is a target for each native module, and if you select react-native-screens then you should be able to see the dependencies.

@LPitonakova
Copy link

Hi @markwilcox sorry I don't see that & after trying a few other things, the error still persists. Here is a screenshot of the Pods -> RNScreens
Screen Shot 2021-06-14 at 4 11 05 PM

My full pod file, of the project is:

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

target 'dopplleHarness' do
  # Pods for dopplleHarness
  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/jscallinvoker', :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'

  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'

  use_native_modules!
  
  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
      end
    end
  end
end




target 'dopplleShare' do
  
  
  use_modular_headers!
  use_native_modules!
  #inherit! :search_paths
  # Manually link packages here to keep your extension bundle size minimal
end

def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
          puts "Fix: " + name
          File.open(name, "w") { |file| file.puts replace }
          STDOUT.flush
      end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end

@markwilcox
Copy link
Contributor

Looking at your linked issue @LPitonakova I think you've gone wrong having use_native_modules! in the share extension target in the first place. The share extension should be all native, no React Native. Extension memory restrictions on iOS make React Native quite unusable inside them. Double check the build instructions for the share extension because I think it shouldn't be including anything at all via Cocoapods.

@LPitonakova
Copy link

Thanks for having a look at that @markwilcox the thing is though, If I take out the use_native_modules! for the share extension target, pods don't install because

[!] The following Swift pods cannot yet be integrated as static libraries:

The Swift pod `react-native-receive-sharing-intent` depends upon `React-Core`, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.

The share extension uses a react native library called react-native-receive-sharing-intent. I even tried the suggestion in the error message, so in my podfile I did:

target 'dopplleShare' do
  use_modular_headers!
end

But the error I get is the same. I am quite lost in this - are you able to see what I am doing wrong? Another weird things is that before XCode 12, I had another project that used the exact same share extension setup, with the use_native_modules! included for the share extension target. That project used to build all ok, even though I cannot build that project anymore either with XCode 12.

@suzTheCoder
Copy link

I have just commented #use_frameworks!
cd ios && pod install
and it worked for me.

@ChiragALogicalloop
Copy link

Sorry, I don't have this problem. Is there anyone else? Is there any problem using this version in a new project?

@sunzhongliangde I'm using it in my project, and adding the pre install action to build RNScreens as a static library causes
Cycle inside FBReactNativeSpec; building could produce unreliable results. This usually can be resolved by moving the shell script phase '[CP-User] Generate Specs' so that it runs before the build phase that depends on its outputs.

It's another problem. Fixed for me with :

post_install do |installer|
  react_native_post_install(installer)
  
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
    end
    
    if (target.name&.eql?('FBReactNativeSpec'))
      target.build_phases.each do |build_phase|
        if (build_phase.respond_to?(:name) && build_phase.name.eql?('[CP-User] Generate Specs'))
          target.build_phases.move(build_phase, 0)
        end
      end
    end
  end
end

It's working for me.
Thanks***

@Biplovkumar
Copy link

@khasbilegt Hi. I've experienced a similar issue and it was related to using use_frameworks! in Podfile.
Try adding the following step to your Podfile:

  pre_install do |installer|
    installer.pod_targets.each do |pod|
      if pod.name.eql?('RNScreens')
        def pod.build_type
          Pod::BuildType.static_library
        end
      end
    end
  end

Thanks it helped me by pass the issue but I would like to know the actual fix and also I would like to know what issues i can expect in future because of this pod file change

It worked. But It is not a good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.