react-native-community / upgrade-support

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

Flipper does not get initialized on iOS - No Application Selected #213

Open xeroxoid opened 2 years ago

xeroxoid commented 2 years ago

Environment

System:
    OS: macOS 12.6
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 27.66 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/Library/Caches/fnm_multishells/65061_1664463546683/bin/node
    Yarn: 1.22.19 - ~/Library/Caches/fnm_multishells/65061_1664463546683/bin/yarn
    npm: 8.13.2 - ~/Library/Caches/fnm_multishells/65061_1664463546683/bin/npm
    Watchman: 2022.09.26.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /Users/milt/.rvm/gems/ruby-2.7.5/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
    Android SDK:
      API Levels: 31
      Build Tools: 30.0.3, 31.0.0
      System Images: android-31 | Google APIs Intel x86 Atom_64
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9014738
    Xcode: 14.0/14A309 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.16.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.1.0 => 18.1.0
    react-native: 0.70.1 => 0.70.1
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Things I’ve done to figure out my issue

Upgrading version

0.70.1

Description

We use the following configuration in our Podfile:


  ...

  project 'XAPP',
    'Debug.Development' => :debug,
    'Release.Development' => :release,
    'Debug.Staging' => :debug,
    'Release.Staging' => :release

  ...

    :flipper_configuration => FlipperConfiguration.enabled(
      ['Debug', 'Debug.Development', 'Debug.Staging'],
      { 'Flipper' => '0.166.0' }),
  ...

After the upgrade to 0.70.1 from 0.68.2 all Flipper specific code was removed from AppDelegate.mm in favour of Flipper getting initialized via <React/RCTAppSetupUtils.h> and RCTAppSetupUtils.mm line 47 i.e.:

void RCTAppSetupPrepareApp(UIApplication *application)
{
#ifdef FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif

...
}

We do use react-native-config to use different environments for Production, Development and, Staging.

The weird thing is that if we do the initialization ourselves on AppDelegate.mm like below (i.e. with the same checks for DEBUG and FB_SONARKIT_ENABLED it works as expected.

...

#if DEBUG
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitLayoutPlugin/SKDescriptorMapper.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#endif
#endif

...

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...

  [self initializeFlipper:application];
  ...
}

- (void) initializeFlipper:(UIApplication *)application {
  #if DEBUG
  #ifdef FB_SONARKIT_ENABLED
    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
  #endif
}

...

It seems like although AppDelegate.mm picks up the FB_SONARKIT_ENABLED and DEBUG variables, RCTAppSetupUtils.mm does not, which is weird.

What we also tried is:

with no success...

We event tried debugging AppDelegate.mm and RCTAppSetupUtils.mm via XCode to figure out the value of FB_SONARKIT_ENABLED but in our understanding this value is evaluated at build/compile time and thus cannot be seen in the debugger.

stratochief66 commented 2 years ago

This resolved the issue for me https://github.com/facebook/react-native/issues/34332#issuecomment-1203201035

pmuthaian commented 1 year ago

@stratochief66 I am having same issue. but unfortunately above thread not solving my issue.

diaraujo13 commented 1 year ago

@stratochief66 I am having same issue. but unfortunately above thread not solving my issue.

Have you find a solution? Same Problem here

skizzo commented 1 year ago

Anybody solved this yet?