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

Question: Try to archive and got error Undefined symbol: _OBJC_CLASS_$_FlipperClient #4471

Closed
auliakbarh opened this issue Jan 30, 2023 · 10 comments

Comments

@auliakbarh
Copy link

Hello everyone!
I've tried to archive my project and got error Undefined symbol: _OBJC_CLASS_$_FlipperClient

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_FlipperClient", referenced from:
      objc-class-ref in libreact-native-flipper.a(FlipperReactNativeJavaScriptPluginManager.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm using:

  • XCode Version 14.2 (14C18)
  • "react-native-flipper": "0.177.0",
  • "react-native": "0.70.5",

in my Podfile:

...
debugs = ['Debug', 'DebugInfra']
...
use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    # Upcoming versions of React Native may rely on get_default_flags(), but
    # we make it explicit here to aid in the React Native upgrade process.
    :hermes_enabled => true,
    :fabric_enabled => flags[:fabric_enabled],
    # Enables Flipper.
    #
    # Note that if you have use_frameworks! enabled, Flipper will not work and
    # you should disable the next line.
    :flipper_configuration => FlipperConfiguration.enabled(debugs, { 'Flipper' => '0.175.0' }),
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )
...

anyone face the same issue?

@auliakbarh
Copy link
Author

This how I fix the issue:

react-native.config.js

module.exports = {
  dependencies: {
    'react-native-flipper': {
      platforms: {
        ios: null,
      },
    },
  },
  ...
}

Podfile

...

  post_install do |installer|
    ...
    apply_flipper_fix(installer)
    ...
  end
  
  def apply_flipper_fix(installer)
    ...
    # Enable Flipper for simulators only
    if target.name.start_with?('Flipper')
      target.build_configurations.each do |config|
        config.build_settings['VALID_ARCHS'] = 'arm64 arm64e'
      end
    end
    ...
  end

AppDelegate.mm

I added && TARGET_OS_SIMULATOR after every DEBUG
example:

#if DEBUG && TARGET_OS_SIMULATOR
#ifdef FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif
#endif

@abejfehr
Copy link

abejfehr commented Mar 23, 2023

This is not resolved, at the very least the Flipper documentation is wrong.

The claim is:

Call FlipperConfiguration.enabled with a specific version in ios/Podfile, for example: :flipper_configuration => FlipperConfiguration.enabled(["Debug"], { 'Flipper' => '0.159.0' }),.

but when you put the following in your Podfile:

flipper_config = FlipperConfiguration.enabled(["Debug"], { 'Flipper' => '0.182.0' })

you still end up with this in XCode:
image

FB_SONARKIT_ENABLED should not be 1 on release builds

Edit: I'll make a new issue with this for visibility

@esbenvb
Copy link

esbenvb commented Sep 26, 2023

In my case, this was solved by installing the proper version of the react-native-flipper npm package.

I could see in the Podfile.lock and gradle.properties the binary Flipper version was 0.125.0 so I did a yarn add react-native-flipper@0.125.0 instead of the default version, and now I can build again :)

@yakupdurmus
Copy link

yakupdurmus commented Oct 20, 2023

In my case, this was solved by installing the proper version of the react-native-flipper npm package.

I could see in the Podfile.lock and gradle.properties the binary Flipper version was 0.125.0 so I did a yarn add react-native-flipper@0.125.0 instead of the default version, and now I can build again :)

I was using version react-native-flipper@0.177.0
I was downgrad to react-native-flipper@0.164.0

It worked

npm install react-native-flipper@0.165.0
cd ios && pod install

@hpelitebook745G2
Copy link

@yakupdurmus thanks, both debug and archive work when i downgraded from:

-    "react-native-flipper": "^0.212.0",
+    "react-native-flipper": "^0.164.0", 

@ah584d
Copy link

ah584d commented Oct 29, 2023

@yakupdurmus thanks, both debug and archive work when i downgraded from:

-    "react-native-flipper": "^0.212.0",
+    "react-native-flipper": "^0.164.0", 

If I downgrade like you suggested in package.json, does it mean that I need also to use an old version of flipper on the computer itself? (dmg file)

@yakupdurmus
Copy link

@yakupdurmus thanks, both debug and archive work when i downgraded from:

  • "react-native-flipper": "^0.212.0",
  • "react-native-flipper": "^0.164.0",

If I downgrade like you suggested in package.json, does it mean that I need also to use an old version of flipper on the computer itself? (dmg file)

I didnt change my desktop flipper application version. Its working.

@sLurPPPeRsTaR
Copy link

well well well i just downgrade to "react-native-flipper": "^0.164.0", from 239 sumthin.. its really givin me a lot of headache, thanks you bless you all

@twboc
Copy link

twboc commented Aug 2, 2024

Undefined symbol: OBJC_CLASS$_FlipperClient
Linker command failed with exit code 1 (use -v to see invocation)

This is an error that caused some confusion and many answers that partially solve the issue but none of them address the issues in a coherent way.

WHAT CAUSES THE ERROR:

In release builds it is caused by trying to line to react-native-flipper library that is not provided for linking yet required in
installer.generated_aggregate_target.xcconfigs

You can find these files in Targets Support Files > Pods-yourAppName in Xcode.
You can find it under OTHER_LDFLAGS with value -l"react-native-flipper"

In my opinion this is an oversight on behalf of the react-native-flipper team.

Most likely in your build output log you will find something like this.:

Undefined symbols for architecture arm64:
"OBJC_CLASS$_FlipperClient", referenced from: in
libreact-native-flipper.a4
ld: symbol(s) not found for architecture arm64 clang: error: linker
command failed with exit code 1 (use -v to see invocation)

If you inspect FlipperReactNativeJavaScriptPluginManager file you will see that it is trying to:

#import <FlipperKit/FlipperClient.h>

And since there is no library to be linked the linker fails and the whole build fails.

YOU MIGHT ALREADY TRIED THIS SOLUTIONS:

use_flipper!(['Debug'])

use_flipper!({'Flipper' => '0.126.0', configurations: ['Debug', 'Dev.Debug']})

:flipper_configuration => FlipperConfiguration.enabled(["Debug"]),
PRODUCTION=1 bundle exec pod install

They might have worked but they are very dependant on the version of react-native-flipper that you use.

use_flipper! - deprecated in newer versions,
FlipperConfiguration.enabled(["Debug"]) - this will not work in older versions.

PRODUCTION=1 - env variable is not always available in your build,

As you can see here the PRODUCTION=1 is available only since this commit:
0c442bf

YET FOR OLDER VERSIONS IT WILL CONTINUE INCLUDES

But still the pods require other pods:
44f5e35#diff-ca0a0286a67452f62d0a79751348c6688482fbce1e93212428494f071904eda1

And going from FlipperKit.podspec
https://github.com/facebook/flipper/blob/main/iOS/Podfile

Which will include Flipper.podspect
https://github.com/facebook/flipper/blob/main/Flipper.podspec

And along the way one of them is going to add that pesky ld flag again.

HOW TO SOLVE THIS ISSUE:
If you are running the newest version of react-native-flipper and have access to build env variables all you have to do is pass

PRODUCTION=1 bundle exec pod install

flag and following this commit it will work.

0c442bf

If you are not so lucky and have to run older version of react-native-flipper you have to delete the linker flag from your release pods

Targets Support Files > Pods-yourAppName You can do it manually just to try out if your build will produce an archive for TestFlight or release

Or add a post install function that will remove the undesired linker flag.

def flipper_remove(generated_aggregate_target, config_name, config_file)
    xcconfig_path = generated_aggregate_target.xcconfig_path(config_name)
    if File.exist?(xcconfig_path)
      puts "FLIPPER: Found xcconfig file: #{File.basename(xcconfig_path)}"
      xcconfig_content = File.read(xcconfig_path)
      modified_content = xcconfig_content.gsub('-l"react-native-flipper"', '')
      File.open(xcconfig_path, 'w') { |file| file.write(modified_content) }
    else
      puts "FLIPPER: xcconfig file does not exist: #{File.basename(xcconfig_path)}"
    end
end

post_install do |installer|
    installer.generated_aggregate_targets.each do |generated_aggregate_target|
        generated_aggregate_target.xcconfigs.each do |config_name, config_file|
            next unless config_name == 'Release'
            flipper_remove(generated_aggregate_target, config_name, config_file)
        end
    end
end

@christophelebris-fulll
Copy link

christophelebris-fulll commented Sep 13, 2024

@twboc => I tried your solution for rn 0.74.5 but still can't archive

Still get the error

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_FKUserDefaultsPlugin", referenced from:
       in AppDelegate.o
  "_OBJC_CLASS_$_FlipperClient", referenced from:
       in AppDelegate.o
  "_OBJC_CLASS_$_FlipperKitNetworkPlugin", referenced from:
       in AppDelegate.o
  "_OBJC_CLASS_$_SKIOSNetworkAdapter", referenced from:
       in AppDelegate.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I did the manual flipper integration as it has been removed in rn 0.74.

I have this in my pod file :

  # Flipper
  pod 'FlipperKit', '~>' + '0.250.0', :configuration => 'Debug'
  pod 'FlipperKit/SKIOSNetworkPlugin', '~>' + '0.250.0', :configuration => 'Debug'
  pod 'FlipperKit/FlipperKitUserDefaultsPlugin', '~>' + '0.250.0', :configuration => 'Debug'
  pod 'Flipper-DoubleConversion', :configuration => 'Debug'
  pod 'Flipper-Folly', :configuration => 'Debug'
  pod 'Flipper-Glog', :configuration => 'Debug'
  pod 'Flipper-PeerTalk', :configuration => 'Debug'
  pod 'CocoaLibEvent', :configuration => 'Debug'
  pod 'boost-for-react-native', :configuration => 'Debug'
  pod 'OpenSSL-Universal', :configuration => 'Debug'
  pod 'CocoaAsyncSocket', :configuration => 'Debug'

and this as recommended by Flipper team

$static_framework = ['FlipperKit', 'Flipper', 'Flipper-Folly',
'CocoaAsyncSocket', 'ComponentKit', 'Flipper-DoubleConversion',
'Flipper-Glog', 'Flipper-PeerTalk', 'Flipper-RSocket', 'Yoga', 'YogaKit',
'CocoaLibEvent', 'OpenSSL-Universal', 'boost-for-react-native', 'Flipper-Fmt']

pre_install do |installer|
  Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
  installer.pod_targets.each do |pod|
      if $static_framework.include?(pod.name)
        def pod.build_type;
          Pod::BuildType.static_library
        end
      end
    end
end

And implementation in my AppDelegate.mm


#import <FlipperKit/FlipperClient.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>


  // init flipper
  FlipperClient *client = [FlipperClient sharedClient];
  [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
  [client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
  [client start];
  

EDIT

Nevermind I found the solution, I just wrapped my code in AppDelegate for DEBUG :

#ifdef DEBUG
 #import <FlipperKit/FlipperClient.h>
 #import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
 #import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
 #import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#endif


 #ifdef DEBUG
   // init flipper
   FlipperClient *client = [FlipperClient sharedClient];
   [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
   [client addPlugin: [[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
   [client start];
 #endif

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

No branches or pull requests

9 participants