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

[unimodules] App doesn't launch on RN 0.62.2 #8723

Closed
mfkrause opened this issue Jun 8, 2020 · 13 comments
Closed

[unimodules] App doesn't launch on RN 0.62.2 #8723

mfkrause opened this issue Jun 8, 2020 · 13 comments

Comments

@mfkrause
Copy link

mfkrause commented Jun 8, 2020

I've tried to set-up unimodules on a bare RN 0.62.2 project. During the configuration process, I've already encountered some differences to the documentation (especially when it comes to Flipper, which has newly been implemented in RN 0.62 and was missing in the example AppDelegate files).
These are my AppDelegate.m and AppDelegate.h as of now:

AppDelegate.m

#import "AppDelegate.h"

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

#import <UMCore/UMModuleRegistry.h>
#import <UMReactNativeAdapter/UMNativeModulesProxy.h>
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.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

@interface AppDelegate () <RCTBridgeDelegate>

@property (nonatomic, strong) UMModuleRegistryAdapter *moduleRegistryAdapter;

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]];
  
#if DEBUG
  InitializeFlipper(application);
#endif

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

  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];
  [super application:application didFinishLaunchingWithOptions:launchOptions];
  return YES;
}

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

- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
{
    NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge];
    // If you'd like to export some custom RCTBridgeModules that are not Expo modules, add them here!
    return extraModules;
}

@end

AppDelegate.h

#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <UMCore/UMAppDelegateWrapper.h>

@interface AppDelegate : UMAppDelegateWrapper <UIApplicationDelegate, RCTBridgeDelegate>

@property (nonatomic, strong) UIWindow *window;

@end

The app does not launch whatsoever. When run from Xcode, it crashes in Pods/FlipperKit/FlipperKitUserDefaultsPlugin/FKUserDefaultsSwizzleUtility.m in line 62 with the code EXC_BAD_ACCESS:

      if (blk != nil) {
        NSString* originalStr =
            [@"comfacebookFlipperKit_" stringByAppendingString:selStr];
        [invocation setSelector:NSSelectorFromString(originalStr)];
        block(invocation); // Crash
      } else {
        ((void (*)(id, SEL, NSInvocation*))orig)(this, fwdSel, invocation);
      }

Here's the dump from the console:

2020-06-08 09:50:38.626942+0200 Intl. SOS TeleDoctor24[15636:4330951] You've implemented -[<UIApplicationDelegate> application:performFetchWithCompletionHandler:], but you still need to add "fetch" to the list of your supported UIBackgroundModes in your Info.plist.
2020-06-08 09:50:38.626982+0200 Intl. SOS TeleDoctor24[15636:4330951] You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
flipper: FlipperClient::addPlugin Inspector
flipper: FlipperClient::addPlugin Preferences
flipper: FlipperClient::addPlugin React
flipper: FlipperClient::addPlugin Network
2020-06-08 09:50:39.000 [info][tid:main][RCTRootView.m:294] Running application internationalsos ({
    initialProps =     {
    };
    rootTag = 1;
})
(lldb) 

(I've already tried to add the two background modes by the way.)
When I disable the line InitializeFlipper(application) in AppDelegate.m, the app then crashes in main.m in line 7:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char * argv[]) {
  @autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); // Crash
  }
}
@todorone
Copy link

todorone commented Jun 8, 2020

Confirming immediate crash on iOS bare workflow project when setting up due to unimodules setup instruction.

@sjchmiela The new instruction(#8683) is much better than previous one, but I guess something is missed in it, bc it leads to crash...

Logs:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.xxx.app 0x000000010189d004 __60-[FKUserDefaultsSwizzleUtility swizzleSelector:class:block:]_block_invoke + 388 (FKUserDefaultsSwizzleUtility.m:62)
1 com.xxx.app 0x0000000101d3c7b4 -[UMAppDelegateWrapper forwardInvocation:] + 404 (UMAppDelegateWrapper.m:25)
2 com.apple.CoreFoundation 0x00007fff23c759f6 ___forwarding___ + 838
3 com.apple.CoreFoundation 0x00007fff23c77f78 _CF_forwarding_prep_0 + 120
4 com.xxx.app 0x00000001012d2efb -[AppDelegate application:didFinishLaunchingWithOptions:] + 763 (AppDelegate.m:59)

UPDATE: Instruction works with the latest expo-unimodules@next, but fails with current stable issue.

@wood1986
Copy link
Contributor

wood1986 commented Jun 8, 2020

see #8706

@sjchmiela
Copy link
Contributor

Hey all, I've just verified that I got Flipper running alongside Unimodules. The project, created by:

is available at https://github.com/sjchmiela/flipper-with-unimodules.

Let me know if this issue still exists or if there's still something wrong! 🙂

@MrFaisal100
Copy link

I am having the exact issue ,, with new project created with RN.0.62.2
I tried to follow the project settings https://github.com/sjchmiela/flipper-with-unimodules but still same issue

@sjchmiela
Copy link
Contributor

The project was created the other way around — first, it was a unimodules project and only then I upgraded it to RN 0.62.2 and added Flipper. How did you initialize your project? I'll try to go through the process like you would do and find the bug this way. Or could you provide me with a preconfigured repository I could clone and tinker around with?

@MrFaisal100
Copy link

If you share you email I would grant you access to my gitlab project

@sjchmiela
Copy link
Contributor

Please contact me on Expo's Slack, the username is @sjchmiela, I'd rather not share my public e-mail in plaintext here. 🙂

@MrFaisal100
Copy link

Messaged you on slack

@sjchmiela
Copy link
Contributor

To fix the problem in @MrFaisal100's project I "just" had to ensure that a recent fix to @unimodules/core is present — #8526.

It adds a window property setter to UMAppDelegateWrapper, the application was crashing due to it missing, see the screenshot:

Zrzut ekranu 2020-06-10 o 14 33 29

In the lower center section you can see selStr equal to "setWindow:", which means that Flipper tries to set the window property.

So, for some (at least) of you, upgrading to react-native-unimodules@0.10.1 (it's available under next tag on NPM already and corresponds to the upcoming SDK 38) should fix the issue. If you'd rather just upgrade @unimodules/core (should be safe), just add it at version ~5.3.0.

To verify if that will fix it, go to UMAppDelegateWrapper.m file (Cmd + Shift + o, enter "UMAppDelegate", select .m and hit enter) and then, add:

 static dispatch_once_t onceToken;
 
 @implementation UMAppDelegateWrapper
+
+@synthesize window = _window;
 
 - (void)forwardInvocation:(NSInvocation *)invocation {

@MrFaisal100
Copy link

Hi
Thanks @sjchmiela for your time and support
This is confirm after upgrading to react-native-unimodules@0.10.1
The issue is resolved
Thanks a lot

@mfkrause
Copy link
Author

Thanks a lot @sjchmiela, updating to the next tag indeed fixed it.
Going to close this issue.

@michtnt
Copy link

michtnt commented Jun 29, 2020

@sjchmiela Thank you so much! I have spent 2 days searching for this problem and yours are the one that actually helped me!

@arun537
Copy link

arun537 commented Jun 29, 2020

Thank You, So much for the fix.

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

No branches or pull requests

8 participants