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

0.71 how to avoid RCTAppDelegate and switch back to old way #35818

Closed
billnbell opened this issue Jan 13, 2023 · 32 comments
Closed

0.71 how to avoid RCTAppDelegate and switch back to old way #35818

billnbell opened this issue Jan 13, 2023 · 32 comments
Assignees
Labels
Component: Switch Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@billnbell
Copy link
Contributor

Description

I want to upgrade to 0.71.

But I have custom PROTOCOLS...

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, RNAppAuthAuthorizationFlowManager, UNUserNotificationCenterDelegate>

How do I ignore RCTAppDelegate and use my own UIResponders?

My build cannot find : RCTAppSetupPrepareApp(application);

I get no found on build.

Version

0.71.0

Output of npx react-native info

no

Steps to reproduce

RCTAppDelegate just remove from AppDelegate

Snack, code example, screenshot, or link to a repository

no

@cipolleschi
Copy link
Contributor

Hi @billnbell There are different solutions to your problem.
One thing you can try is actually to replace UIResponder with RCTAppDelegate

-@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, RNAppAuthAuthorizationFlowManager, UNUserNotificationCenterDelegate>
+@interface AppDelegate : RCTAppDelegate <UIApplicationDelegate, RCTBridgeDelegate, RNAppAuthAuthorizationFlowManager, UNUserNotificationCenterDelegate>

RCTAppDelegate extends UIResponder, so you can use it instead of UIResponder.
This is the suggested approach as it will allow you to benefit for future updates for free: if we change something internally in the RCTAppDelegate, you won't have to do anything manually to migrate to the new version and will benefit from the changes.

On the other end, RCTAppDelegate is completely optional. You don't need to use it. If you don't want it, just keep your old implementation and everything should work as before. But you will have to always do some manual steps to migrate your app.

Let me know if it works.

@billnbell
Copy link
Contributor Author

OK - do I need all or just the new ones? I did the following and it appeared to work ok ?

I dropped UIApplicationDelegate, RCTBridgeDelegate

#import <RCTAppDelegate.h>
#import <UIKit/UIKit.h>

#import <UserNotifications/UNUserNotificationCenter.h>
#import "RNAppAuthAuthorizationFlowManager.h"

@interface AppDelegate : RCTAppDelegate <RNAppAuthAuthorizationFlowManager, UNUserNotificationCenterDelegate>

@property (nonatomic, weak) id<RNAppAuthAuthorizationFlowManagerDelegate>authorizationFlowManagerDelegate;

@property (nonatomic, strong) UIWindow *window;

@end

@cipolleschi
Copy link
Contributor

I dropped UIApplicationDelegate, RCTBridgeDelegate

Yep, you can drop these as RCTAppDelegate implements them already.

do I need all or just the new ones?

What do you mean with all and just the new ones? 😅 Sorry, but I'm not sure I'm following here...

I did the following and it appeared to work ok ?

The changes looks good to me. What you should also do is to remove all the implementation code that you may have in your AppDelegate.mm and that we moved to the RCTAppDelegate.mm (the same code the upgrade-helper show you to remove, basically - here and ⌘+f for AppDelegate.mm to see all the removed code.)
All that code has been moved to the RCTAppDelegate, so you can safely remove it from your app as soon as you remember to call the methods on the super class, for example

// In your AppDelegate.mm
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // Replace `HelloWorld` with the name of your app
  self.moduleName = @"HelloWorld";
  // put all your initialization code here
  // ...
  // Remember to invoke super to initialize React Native.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

Let me know if it works!

@Dhimassudaryanta
Copy link

Hi @billnbell There are different solutions to your problem. One thing you can try is actually to replace UIResponder with RCTAppDelegate

-@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, RNAppAuthAuthorizationFlowManager, UNUserNotificationCenterDelegate>
+@interface AppDelegate : RCTAppDelegate <UIApplicationDelegate, RCTBridgeDelegate, RNAppAuthAuthorizationFlowManager, UNUserNotificationCenterDelegate>

RCTAppDelegate extends UIResponder, so you can use it instead of UIResponder. This is the suggested approach as it will allow you to benefit for future updates for free: if we change something internally in the RCTAppDelegate, you won't have to do anything manually to migrate to the new version and will benefit from the changes.

On the other end, RCTAppDelegate is completely optional. You don't need to use it. If you don't want it, just keep your old implementation and everything should work as before. But you will have to always do some manual steps to migrate your app.

Let me know if it works.

This is work, thank you very much!

@TomarVidhi04
Copy link

Hi @billnbell There are different solutions to your problem. One thing you can try is actually to replace UIResponder with RCTAppDelegate

-@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, RNAppAuthAuthorizationFlowManager, UNUserNotificationCenterDelegate>
+@interface AppDelegate : RCTAppDelegate <UIApplicationDelegate, RCTBridgeDelegate, RNAppAuthAuthorizationFlowManager, UNUserNotificationCenterDelegate>

RCTAppDelegate extends UIResponder, so you can use it instead of UIResponder. This is the suggested approach as it will allow you to benefit for future updates for free: if we change something internally in the RCTAppDelegate, you won't have to do anything manually to migrate to the new version and will benefit from the changes.
On the other end, RCTAppDelegate is completely optional. You don't need to use it. If you don't want it, just keep your old implementation and everything should work as before. But you will have to always do some manual steps to migrate your app.
Let me know if it works.

This is work, thank you very much!

Screenshot 2023-04-19 at 2 08 56 PM

i am facing same problem RCTAppDelegate.h file not found

@cipolleschi
Copy link
Contributor

@TomarVidhi04 hi there! Just to make sure that the setup is correct: did you update React Native, run Yarn and reinstall the pods with bundle exec pod install?

It could be that you forgot one of the above steps and React Native did not downloaded the file.

To make sure about that, can you check whether in the Pods project, Development Pods, you have a folder called React-AppDelegate and that it contains that header?

@tomwanzek
Copy link

@TomarVidhi04 As for the RCTAppDelegate.h file not found when building issue, I might have a suggestion to check:

Is it possible to build the project from the command line with yarn ios? If so and the matter is purely an Xcode build issue, then it may simply be the following:

Make sure to open the workspace (xcworkspace file) in Xcode, not just the project for the app itself. The workspace includes the

Pods project, Development Pods

with the React-RCTAppDelegate directory w/ header files and all the trimmings as mentioned by @cipolleschi 😄

If you opened only the xcodeproj file with XCode it won't find the pods project.

Once you build the project from within the opened workspace, it should be fine. Hopefully that does the trick. 🤞

@ucheNkadiCode
Copy link

ucheNkadiCode commented May 5, 2023

From your advice, I actually looked at my Pods -> Development Pods and saw that after upgrading from RN 0.69.10 -> 71.7 I actually was missing my React-RCTAppDelegate pod.

After that I tried pod deintegrate then pod install

But I'm still getting

'React/RCTEventEmitter.h' file not found and RCTAppDelegate.h file not found . I literally see RCTAppDelegate.h right there but it says it's not found. I'm unsure of why RCT-EventEmitter is also not being found all of a sudden

Screenshot 2023-05-05 at 5 44 14 AM

Also, even in RCTAppDelegate pod, RCTBridge.h is not being found
Screenshot 2023-05-05 at 5 52 46 AM

please help when you can. Is there an earlier version of 71 that might work for M1?

@cipolleschi
Copy link
Contributor

Hi @ucheNkadiCode. Version 0.71.7 works properly. There is something dirty in your system.

Please try to:

  1. cd <yourApp>
  2. yarn // <--- to make sure that you have the most updated scripts
  3. rm <yourApp>/ios/build // <-- Remove the build folder created by codegen
  4. cd ios
  5. pod install

At this point, you should have the most recent scripts, a clean situation and the most recent pods for your version.

Let me know if this works!

@ucheNkadiCode
Copy link

Hey @cipolleschi Thank for your help!

Now my app is able to properly find RCTApp delegate! for some reason however,

In my AppName-Bridging-Header I'm still seeing 'react/RCTEventEmitter.h file not found'. It's also still not in my react pods either

Screenshot 2023-05-05 at 4 30 30 PM

@cipolleschi
Copy link
Contributor

cipolleschi commented May 9, 2023

Hi @ucheNkadiCode, I think you can safely remove that line from the the bridging headers. We are not generating that file, Cocoapods/Xcode does that automatically. So, probably, it has been generated when you were having trouble compiling/building. Let's try to remove the line and see what happens.

You should also have that file, though. It should be in the Development Pods/React-Core/Default/Modules path:
Screenshot 2023-05-09 at 11 11 06

This is a new App I created from 0.71.7.

@anhdo9797
Copy link

anhdo9797 commented Jun 23, 2023

Hi @ucheNkadiCode. Version 0.71.7 works properly. There is something dirty in your system.

Please try to:

  1. cd <yourApp>
  2. yarn // <--- to make sure that you have the most updated scripts
  3. rm <yourApp>/ios/build // <-- Remove the build folder created by codegen
  4. cd ios
  5. pod install

At this point, you should have the most recent scripts, a clean situation and the most recent pods for your version.

Let me know if this works!

Hi @cipolleschi, I have applied all your solutions but it doesn't work. Can you give me more solutions?

I upgraded React native version from 0.64 to 0.7.18. I have no problem in Pod/Development Pod/React-RCT
Screen Shot 2023-06-23 at 10 19 42

but I get an error 'RCTAppDelegate.h' file not found in my AppDelegate.h

Screen Shot 2023-06-23 at 10 18 34

This is my Podfile:

project ‘MyApp’,
        'Debug' => :debug,
        'QARelease' => :release,
        'Release' => :release

target 'MyApp' do

  config = use_native_modules!
  
  # Flags change depending on the env values.
  flags = get_default_flags()

  # This has to come before use_react_native or you get AppDelegate or RCTEventEmitter not found
  use_frameworks! :linkage => :static

  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 => flags[:hermes_enabled],
    :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 => flipper_config,
    # An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  pod 'FirebaseCore', :modular_headers => true
  pod 'FirebaseCoreExtension', :modular_headers => true
  pod 'FirebaseInstallations', :modular_headers => true
  pod 'GoogleDataTransport', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  pod 'nanopb', :modular_headers => true

  post_install do |installer|
    react_native_post_install(
      installer,
      # Set `mac_catalyst_enabled` to `true` in order to apply patches
      # necessary for Mac Catalyst builds
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)
  end
  
end

@cipolleschi
Copy link
Contributor

cipolleschi commented Jun 23, 2023

Hi @anhdo9797.

First of all, notice that Flipper is incompatible with frameworks, so you'd have to set this:
:flipper_configuration => FlipperConfiguration.disabled

Then, I did some tests:

  1. created a new app from the latest version of 0.71 (which is 0.71.10)
  2. installed pods with USE_FRAMEWORKS=static NO_FLIPPER=1 bundle exec pod install => the error appeared but then Xcode was able to resolve it and the build was successful
  3. changed the podfile adding use_frameworks! :linkage => :static before use_react_native!
  4. reinstalled the pods with NO_FLIPPER=1 bundle exec pod install
  5. cleaned the project with K
  6. Rebuild, and it worked.

I'm start thinking that the problem could come from some of your dependency, as a vanilla project works as expected.

As tentative test, given that I cant repro it locally, could you try to apply this change in your AppDelegate.h file?

-#import <RCTAppDelegate.h>
+#import <React_RCTAppDelegate/RCTAppDelegate.h>

In theory, Xcode should be able to resolve the <RCTAppDelegate.h>, but it may need some help if some dependency is messing with the search paths.

@anhdo9797
Copy link

Hi @anhdo9797.

First of all, notice that Flipper is incompatible with frameworks, so you'd have to set this: :flipper_configuration => FlipperConfiguration.disabled

Then, I did some tests:

  1. created a new app from the latest version of 0.71 (which is 0.71.10)
  2. installed pods with USE_FRAMEWORKS=static NO_FLIPPER=1 bundle exec pod install => the error appeared but then Xcode was able to resolve it and the build was successful
  3. changed the podfile adding use_frameworks! :linkage => :static before use_react_native!
  4. reinstalled the pods with NO_FLIPPER=1 bundle exec pod install
  5. cleaned the project with ⌘⇪K
  6. Rebuild, and it worked.

I'm start thinking that the problem could come from some of your dependency, as a vanilla project works as expected.

As tentative test, given that I cant repro it locally, could you try to apply this change in your AppDelegate.h file?

-#import <RCTAppDelegate.h>
+#import <React_RCTAppDelegate/RCTAppDelegate.h>

In theory, Xcode should be able to resolve the <RCTAppDelegate.h>, but it may need some help if some dependency is messing with the search paths.

Thank @cipolleschi, It works for me

@enisinanaj
Copy link

enisinanaj commented Jul 4, 2023

2. USE_FRAMEWORKS=static NO_FLIPPER=1 bundle exec pod install

I have the exact same issue. I upgraded from 0.69 to 0.71 and I'm continuously having this issue for iOS. Android works fine.
I checked the header search paths and it should be all fine.

Since I'm also using Firebase via the react-native-firebase project I cannot use Flipper as I need to use frameworks.

I see React-AppDelegate project in my pods directory.
I tried step by step what you wrote here but I still get the issue. Do you have please any other hints?

Cheers!

@cipolleschi
Copy link
Contributor

Can you try to use this import statement in your AppDelegate?

-#import <RCTAppDelegate.h>
+#import <React_RCTAppDelegate/RCTAppDelegate.h>

@enisinanaj
Copy link

enisinanaj commented Jul 4, 2023

Same error with his change as well unfortunately.

Screenshot 2023-07-04 at 16 37 12

@cipolleschi
Copy link
Contributor

could you try to set up a minimal reproducer using this repo This is a recurring problem, so I really want to solve it once and for all, but not using Firebase directly, I don't know which steps to follow to reproduce it.

@enisinanaj
Copy link

i will try to do that. But generally a new project with the same rn version 0.71 worked fine when i tried some weeks ago.

@enisinanaj
Copy link

Hi, I cannot reproduce it with the repo or a new project. After adding all my dependencies it just builds and runs.
I checked and double-checked all search paths, deintegrated the pods and installed them again but I'm having the same issue.
Any other ideas please?

@billnbell
Copy link
Contributor Author

  1. USE_FRAMEWORKS=static NO_FLIPPER=1 bundle exec pod install

I have the exact same issue. I upgraded from 0.69 to 0.71 and I'm continuously having this issue for iOS. Android works fine. I checked the header search paths and it should be all fine.

Since I'm also using Firebase via the react-native-firebase project I cannot use Flipper as I need to use frameworks.

I see React-AppDelegate project in my pods directory. I tried step by step what you wrote here but I still get the issue. Do you have please any other hints?

Cheers!

Bust open Xcode and build from there. Most of the time it will give you more errors.

@billnbell
Copy link
Contributor Author

Hi, I cannot reproduce it with the repo or a new project. After adding all my dependencies it just builds and runs.
I checked and double-checked all search paths, deintegrated the pods and installed them again but I'm having the same issue.
Any other ideas please?

I know it sounds stupid - but reboot.

@enisinanaj
Copy link

Hi, I cannot reproduce it with the repo or a new project. After adding all my dependencies it just builds and runs.
I checked and double-checked all search paths, deintegrated the pods and installed them again but I'm having the same issue.
Any other ideas please?

I know it sounds stupid - but reboot.

I had hopes about this but seems to have no effect :(

@enisinanaj
Copy link

enisinanaj commented Jul 19, 2023

Hi, I cannot reproduce it with the repo or a new project. After adding all my dependencies it just builds and runs.
I checked and double-checked all search paths, deintegrated the pods and installed them again but I'm having the same issue.
Any other ideas please?

I know it sounds stupid - but reboot.

tried building both from the command line and from xcode. but I have the same issue... am I right in assuming that it has something to do with the search paths?

@cipolleschi
Copy link
Contributor

Not really, it has to do with how Xcode packages the frameworks and where the files are put. which influences the header search path, but that's not the root cause.

  1. do you have this line in your app header_search_paths?
Screenshot 2023-07-20 at 13 24 51
  1. Are you using pnpm or plain npm?
  2. Do you have these folders in your derived data?
Screenshot 2023-07-20 at 13 35 44
  1. Is this the only error you are seeing in the build? Sometimes there are multiple errors and those are the actual responsible for the error (for example, another framework can't be build, so RCTAppDelegate can't be build and the app can't find the header).
  2. Are you using also swift, maybe? In some cases the Objective-C/Swift interop may create issues and therefore we can have to use a different import (look here for more info)

@github-actions github-actions bot added the Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. label Jul 20, 2023
@enisinanaj
Copy link

Not really, it has to do with how Xcode packages the frameworks and where the files are put. which influences the header search path, but that's not the root cause.

  1. do you have this line in your app header_search_paths?
Screenshot 2023-07-20 at 13 24 51 2. Are you using pnpm or plain npm? 3. Do you have these folders in your derived data? Screenshot 2023-07-20 at 13 35 44 4. Is this the only error you are seeing in the build? Sometimes there are multiple errors and those are the actual responsible for the error (for example, another framework can't be build, so RCTAppDelegate can't be build and the app can't find the header). 5. Are you using also swift, maybe? In some cases the Objective-C/Swift interop may create issues and therefore we can have to use a different import (look [here](https://github.com/react-native-community/RNNewArchitectureLibraries/issues/15) for more info)

Hi @cipolleschi, first of all thanks a lot for the detailed input.

  1. Yes I do have that line.

  2. Just plain npm

  3. No that I don't have

  4. Building from Xcode that is the only error. While building from the command line I had a second one about Firebase
    After some investigation then I came across 'FirebaseCore/FIRAnalyticsConfiguration.h' file not found on v5 invertase/react-native-firebase#1106 (comment) so I removed use_frameworks from the podfile and followed your initial guide. I had to do some further adjustments but finally, I managed to run it (on a real device). On the simulator, I still have the same issue but I can figure it out from here (I think).

  5. I am also using Swift but that works as looks like

@cipolleschi
Copy link
Contributor

If you managed to run it on a real device but not a simulator, try to cleanup the derived data. It could be that Xcode has something cached for the simulator builds that makes those build fail.

@zinzaducnm
Copy link

zinzaducnm commented Sep 27, 2023

In my case, I created multiple targets, and header search paths of these target missed some value for example "${PODS_CONFIGURATION_BUILD_DIR}/React-RCTAppDelegate/React_RCTAppDelegate.framework/Headers"
I try to create abstract_target, my targets are inside the abstract_target.
Remember to remove Pods/, Podfile.lock, and pod install again then I can build without any error.
Hope this helps!

@jpouabou
Copy link

Hi,

I have literally tried every solution there is on GitHub and stack overflow regarding this error and nothing works for me. I'm on 0.72.7 and I am also getting the AppDelegate.h not found issue.
I have spent 2 days on this and I am thinking about going to back to an old version before this issue arose.
I am not sure what steps to take to even attempt to solve this because every solution I have tried is not working. I am on Apple M2 Chip.

@cipolleschi
Copy link
Contributor

Hi @jpouabou, I'm sorry you are hitting this problem.

A few questions to help you out:

  1. If you create a new app from 0.72.7, does the problem persist?
  2. Can you try the following:
    1. Navigate to your app's ios folder, then run:
    bundle install
    bundle exec pod deintegrate
    bundle exec pod install
    
    1. Open the <YourAppName>.xcworkspace file
    2. Try to build and see whether the problem persist
  3. Is your app's Podfile similar to the template one?
  4. Can you share it?
  5. Can you share the list of 3rd party libraries you are using?
  6. Can you post the precise error you are seeing in Xcode?

@developersflex
Copy link

Hello,

I'm just getting the same error but on xcode cloud. Does the above solutions work on xcode cloud?

@cipolleschi
Copy link
Contributor

Hi @developersflex! I think it depends on the error. I have never used Xcode cloud, so I don't know what you can do on/with it.
In theory, it could/should, but this error depends more on the specific App setup (3rd party libraries not properly set up) than on React Native.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Switch Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests