invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.69k stars 2.21k forks source link

[🐛] [iOS] - Crashlytics not reading firebase.json first crash of the app doesn't activate the service #7623

Closed stefandbd closed 8 months ago

stefandbd commented 8 months ago

Issue

Hello,

Seems that my app doesn't start Crashlytics when I do a crashlytics().crash() . Left all the environment, firebase json, pods down below. Here is the Xcode output that suggest me it doesn't see/read the firebase.json file:

+[RNFBSharedUtils getConfigBooleanValue:key:defaultValue:] [Line 162] RNFBCrashlyticsInit crashlytics_debug_enabled via RNFBMeta: 0
+[RNFBSharedUtils getConfigBooleanValue:key:defaultValue:] [Line 165] RNFBCrashlyticsInit crashlytics_debug_enabled final value: 0
+[RNFBCrashlyticsInitProvider isCrashlyticsCollectionEnabled] [Line 49] RNFBCrashlyticsInit isCrashlyticsCollectionEnabled after checking crashlytics_debug_enabled: 0
Crashlytics - INFO: crashlytics collection is not enabled, not crashing.

PS: Analytics works fine. Also, I'm running on a M2 Max with: pod --version: 1.14.3 ruby -v: ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]

PS2: I did run pod install fresh after adding the firebase.json file

PS3: In crashlytics dashboard it says: App detected and we're waiting for a crash!

PS4: I did realease a TestFlight version also to crash it, 24h ago, app crashed, but still not started the crashlytics on the dashboard

PS5: Android works fine

What can be wrong?


Project Files

Javascript

Click To Expand

#### `package.json`: ```json {... "@react-native-firebase/analytics": "^18.8.0", "@react-native-firebase/app": "^18.8.0", "@react-native-firebase/crashlytics": "^18.8.0", ...} ``` #### `firebase.json` for react-native-firebase v6: ```json { "react-native": { "crashlytics_debug_enabled": true, "crashlytics_disable_auto_disabler": true, "crashlytics_auto_collection_enabled": true, "crashlytics_is_error_generation_on_js_crash_enabled": true, "crashlytics_javascript_exception_handler_chaining_enabled": false, "android_bypass_emulator_url_remap": true } } ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # Resolve react_native_pods.rb with node to allow for hoisting def node_require(script) # Resolve script with node to allow for hoisting require Pod::Executable.execute_command('node', ['-p', "require.resolve( '#{script}', {paths: [process.argv[1]]}, )", __dir__]).strip end node_require('react-native/scripts/react_native_pods.rb') node_require('react-native-permissions/scripts/setup.rb') platform :ios, min_ios_version_supported prepare_react_native_project! # ⬇️ uncomment wanted permissions setup_permissions([ # 'AppTrackingTransparency', # 'BluetoothPeripheral', # 'Calendars', 'Camera', # 'Contacts', 'FaceID', 'LocationAccuracy', 'LocationAlways', 'LocationWhenInUse', # 'MediaLibrary', # 'Microphone', # 'Motion', 'Notifications', # 'PhotoLibrary', # 'PhotoLibraryAddOnly', # 'Reminders', # 'Siri', # 'SpeechRecognition', # 'StoreKit', ]) # If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set. # because `react-native-flipper` depends on (FlipperKit,...) that will be excluded # # To fix this you can also exclude `react-native-flipper` using a `react-native.config.js` # ```js # module.exports = { # dependencies: { # ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}), # ``` flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled linkage = ENV['USE_FRAMEWORKS'] if linkage != nil Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green use_frameworks! :linkage => linkage.to_sym end target 'MyTarget' do use_frameworks! :linkage => :static config = use_native_modules! # Flags change depending on the env values. flags = get_default_flags() 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 => FlipperConfiguration.enabled, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) pod 'Firebase', :modular_headers => true pod 'FirebaseCore', :modular_headers => true pod 'GoogleUtilities', :modular_headers => true target 'MyTargetDEV' do inherit! :complete end target 'MyTargetSTAGING' do inherit! :complete end target 'MyTargetTESTS' do inherit! :complete # Pods for testing end post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['ENABLE_BITCODE'] = 'NO' end if target.name == "lottie-ios" target.build_configurations.each do |config| config.build_settings['ENABLE_BITCODE'] = 'NO' config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO' config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES' end end end 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 ``` #### `AppDelegate.m`: ```objc // N/A ```



Environment

Click To Expand

**`react-native info` output:** ``` (node:50225) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency (Use `node --trace-warnings ...` to show where the warning was created) System: OS: macOS 14.2.1 CPU: (12) arm64 Apple M2 Max Memory: 1.13 GB / 32.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 18.17.1 path: /usr/local/bin/node Yarn: version: 1.22.19 path: /opt/homebrew/bin/yarn npm: version: 9.6.7 path: /usr/local/bin/npm Watchman: version: 2023.11.27.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.14.3 path: /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: - DriverKit 23.2 - iOS 17.2 - macOS 14.2 - tvOS 17.2 - visionOS 1.0 - watchOS 10.2 Android SDK: Not Found IDEs: Android Studio: 2022.3 AI-223.8836.35.2231.10671973 Xcode: version: 15.2/15C500b path: /usr/bin/xcodebuild Languages: Java: version: 11.0.20.1 path: /usr/bin/javac Ruby: version: 2.6.10 path: /usr/bin/ruby npmPackages: "@react-native-community/cli": Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.72.4 wanted: 0.72.4 react-native-macos: Not Found npmGlobalPackages: "*react-native*": Not Found Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: true newArchEnabled: false ``` - **Platform that you're experiencing the issue on**: - [x] iOS - [ ] Android - [x] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `e.g. 18.8.0` - **`Firebase` module(s) you're using that has the issue:** - `Firebase 10.20.0` - `Analytics 10.20.0` - `Core 10.20.0` - `Crashlytics 10.20.0` - **Are you using `TypeScript`?** - `Y`


mikehardy commented 8 months ago

After altering firebase.json you have to re-run pod install - the transformation from "I changed a setting in firebase.json" into something the app can see happens via a shell script that is called as part of the pod installation process

I forget to do this from time to time and it has the results you describe ("I changed it! Why isn't it changing !?")

I'm confident enough in that guess I'm going to close this but that's an easily reversible decision on my part we can reopen if you run pod install and still don't see the results you expect

fxricky commented 5 months ago

hi @mikehardy , I'm currently facing this issue in ios platform.

machine

macos : Ventura 13.2.1

project package versions

"react-native": "0.73.4",
"@react-native-firebase/app": "^19.2.2",
"@react-native-firebase/crashlytics": "^19.2.2"

I've update the firebase.json to following config

{
  "react-native": {
    "crashlytics_debug_enabled": true,
    "crashlytics_disable_auto_disabler": true,
    "crashlytics_auto_collection_enabled": true,
    "crashlytics_is_error_generation_on_js_crash_enabled": true,
    "crashlytics_javascript_exception_handler_chaining_enabled": true
  }
}

after these changes, I deleted the Pods , Podfile.lock, and run pod install everything looks fine at this point of time

...
Installing Firebase (10.24.0)
Installing FirebaseCore (10.24.0)
Installing FirebaseCoreExtension (10.25.0)
Installing FirebaseCoreInternal (10.25.0)
Installing FirebaseCrashlytics (10.24.0)
Installing FirebaseInstallations (10.25.0)
Installing FirebaseRemoteConfigInterop (10.25.0)
Installing FirebaseSessions (10.25.0)
...

then I deleted the apps and reinstall it thru terminal, successfully built and show in the simulator

however, when I try to trigger crashlytics().crash(), the log shows error below

2024-05-08 22:09:45.376 [app_name][34012:1d5e371] +[RNFBCrashlyticsInitProvider configureWithApp:] [Line 101] RNFBCrashlyticsInit initialization successful
2024-05-08 22:09:45.376 Db [app_name][26842:1d4d36a] [com.apple.defaults:User Defaults] found no value for key crashlytics_debug_enabled in CFPrefsSearchListSource<0x600001215180> (Domain: io.invertase.firebase, Container: (null))
2024-05-08 22:09:45.376 Df [app_name][26842:1d4d36a] +[RNFBSharedUtils getConfigBooleanValue:key:defaultValue:] [Line 162] RNFBCrashlyticsInit crashlytics_debug_enabled via RNFBMeta: 0
2024-05-08 22:09:45.376 Df [app_name][26842:1d4d36a] +[RNFBSharedUtils getConfigBooleanValue:key:defaultValue:] [Line 165] RNFBCrashlyticsInit crashlytics_debug_enabled final value: 0
2024-05-08 22:09:45.376 Df [app_name][26842:1d4d36a] +[RNFBCrashlyticsInitProvider isCrashlyticsCollectionEnabled] [Line 49] RNFBCrashlyticsInit isCrashlyticsCollectionEnabled after checking crashlytics_debug_enabled: 0
2024-05-08 22:09:45.376 I  [app_name][26842:1d4d36a] [com.facebook.react.log:native] Crashlytics - INFO: crashlytics collection is not enabled, not crashing.

I have checked with crashlytics().app, and I can see all the values matched with those in dashboard

is there any logs / info that I can provide to help to investigate this issue?

I have yet to try it in Release mode, currently I'm working in Debug mode to verify if this is working FYI, I've done the same setting to Android, and the crash() is working, and I'm seeing the logs in the dashboard

mikehardy commented 5 months ago

@fxricky your firebase.json looks good, you are doing the pod install, but when you run it and check the logs (exactly the correct thing to do!) you are not seeing the output you expect. I put those logs in there for this precise reason - so you could positively confirm that your config was in place (or not!). Looks like it is not in place. Why not? I do not know. It looks like something about the "pod install" / "build the app" / "run the app you built" thing isn't happening.

You can verify that the pod install got the correct firebase.json in there by searching for the processed Info.plist that is made by pod install, and is then packaged into the app.

For me that looks like this:

1) getting the contacts of the file: cat ios/build/Build/Products/Debug-iphonesimulator/testing.app/Info.plist 2) searching down to the firebase_json_raw key and seeing a base64-encoded string 3) copying that string into your clipboard so you can then paste it into a command line that looks something like this:

echo eyJhb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5fZmFsc2UiOiBmYWxzZSwgInJuZmlyZWJhc2VfanNvbl90ZXN0aW5nX2Jvb2xlYW5fdHJ1ZSI6IHRydWV9 | base64 --decode | jq -r |grep crashlytics

(that is: "base64-decode that firebase_json_raw key value, send it through the jq command to pretty-print it, then grep out / only display the crashlytics keys")

You should see something like

  "crashlytics_ndk_enabled": true,
  "crashlytics_debug_enabled": true,
  "crashlytics_disable_auto_disabler": true,
  "crashlytics_auto_collection_enabled": true,
  "crashlytics_is_error_generation_on_js_crash_enabled": true,
  "crashlytics_javascript_exception_handler_chaining_enabled": false,

If you do not see that, then pod install did not find your firebase.json for some reason and you should pay very close attention to your build output to determine exactly why: it will tell you where it searched and where it found the file or if it did not find it

If you do see that, then it should get built in to the app, and if it is built in to the app but you are still not seeing it in the logging output, then you are not running the app you built, somehow, for some reason - I don't know

That's how I troubleshoot these things anyway - I've never had to do more than those two investigative steps before the chain of "firebase.json -> app" was fully working

Hope this helps

fxricky commented 5 months ago

hi @mikehardy , from the output log, I can see it is using the correct firebase.json

Using firebase.json from '<project_path>/firebase.json'

however, when I try to view the .app package-content > info.plist, I don't see the key you mentioned

I'm now run out of idea on how should I continue to tackle this issue

mikehardy commented 5 months ago

@fxricky you're getting closer.

during pod-install, the file ios-config.sh should be configured to run and built and at build it should inject that key into the Info.plist

The call chain looks like this:

1) we configure react-native CLI to make ios-config.sh a script phase for Xcode that runs after compile:

https://github.com/invertase/react-native-firebase/blob/9fe3e4b698ff867fcdf9689ea23e1396a94ddaba/packages/app/react-native.config.js#L8-L15

2) ios-config will do it's work and log the output in the Xcode build log - you can examine it's contents here https://github.com/invertase/react-native-firebase/blob/main/packages/app/ios_config.sh

That work in step 2 involves locating the firebase.json file, finding the target plist file, and copying data from one to the other

Your next step is to locate the full Xcode build log and find this line then see where things go wrong such that your firebase.json isn't copied in to your app by the script at build time

https://github.com/invertase/react-native-firebase/blob/9fe3e4b698ff867fcdf9689ea23e1396a94ddaba/packages/app/ios_config.sh#L70

fxricky commented 5 months ago

@mikehardy , I've spent few days debugging this, but I still can't find any build logs that echo the line that you mentioned above..

mikehardy commented 5 months ago

I can see it on the command line by invoking xcodebuild directly, redirecting output to a log and investigating, i.e.


mike@isabela:~/work/invertase/react-native-firebase/tests (@mikehardy/dependency-updates *) % set -o pipefail && xcodebuild VALID_ARCHS=\"`uname -m`\"  CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ -workspace ios/testing.xcworkspace -scheme testing -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build > build.log 2>&1
mike@isabela:~/work/invertase/react-native-firebase/tests (@mikehardy/dependency-updates *) % cat build.log |grep 'RNFB build script started'
info: -> RNFB build script started
fxricky commented 5 months ago

@mikehardy so sad to tell you, that it does not echo any line from the build.log 😢

image

mikehardy commented 5 months ago

Then the script is not being installed as a post installation run script in your xcworkspace during pod install, for unknown reasons. Examine pod install process, and xcworkspace build steps and scripts etc

fxricky commented 4 months ago

spent quite some times on this, but still unable to find anything from this 😞

fxricky commented 4 months ago

hi @mikehardy , I can see the shell script exist in the project.pbxproj, I can also see the GoogleService-Info.plist in the app package. Is there any way I can continue inspect on this?

btw, I'm on M1 mac, using rvm: ruby-3.1.2

I also has a script that used to deal with multiple target in my application

Looking for GoogleService-Info.plist in /Users/user/Development/xyz/ios/xyz/Firebase/dev/GoogleService-Info.plist
Will copy GoogleService-Info.plist to final destination: /Users/user/Development/xyz/ios/build/Build/Products/Debug-iphonesimulator/xyzDev.app
Using /Users/user/Development/xyz/ios/xyz/Firebase/dev/GoogleService-Info.plist
raajeshmani commented 2 weeks ago

Too late of a reply @fxricky. Just putting it out here so I can come back to this after a couple of months

The problem with RNFB script not executing in my case was my Pods/Pods.xcodeproj/project.pbxproject had a different IPHONEOS_DEPLOYMENT_TARGET and didn't update even if i change my app's deployment target.

I fixed it by running

pod deintegrate
pod setup
pod install

Post that I could see this in my build log

debug info: -> RNFB build script started
info: 1) Locating firebase.json file: