Skip to content

fix(crashlytics): pass setCrashlyticsCollectionEnabled to the native SDK immediately - #9529

Open
harpreetkbadhan wants to merge 3 commits into
invertase:mainfrom
harpreetkbadhan:fix/crashlytics-collection-now
Open

harpreetkbadhan wants to merge 3 commits into
invertase:mainfrom
harpreetkbadhan:fix/crashlytics-collection-now

Conversation

@harpreetkbadhan

@harpreetkbadhan harpreetkbadhan commented Nov 26, 2026 •

Copy link
Copy Markdown

Description

setCrashlyticsCollectionEnabled only wrote the module's preference. The SDK reads that preference once, when the init provider starts, so on iOS a consent withdrawal reached report handling only at the second launch after it.

The method now also calls the SDK's own switch at once, FirebaseCrashlytics.getInstance().setCrashlyticsCollectionEnabled(...) on Android and [[FIRCrashlytics crashlytics] setCrashlyticsCollectionEnabled:] on iOS, which both SDKs persist themselves. The SDK's saved value is then already correct at the next start, so the extra launch on iOS goes away.

Firebase guarantees this switch from the next app launch (FIRCrashlytics.h, and the FirebaseCrashlytics javadoc for false), so the docs and the JSDoc say that, and do not promise anything for crashes later in the same run.

On Android the two steps live in a package-private static helper, NativeRNFBTurboCrashlytics.saveAndApplyCollectionEnabled, so a JVM test can call it. It passes the module's computed value (isCrashlyticsCollectionEnabled()), not the raw enabled argument, after writing the preference. That keeps the existing rule that a debug build stays off unless crashlytics_debug_enabled is set in firebase.json, which the docs already state.

On iOS the call goes through a new RNFBCrashlyticsHelper method, since RNFBCrashlyticsModule.mm routes every Crashlytics SDK call through that ObjC helper. The usage docs get one bullet under Opt-out, and the setCrashlyticsCollectionEnabled JSDoc says when the value applies.

Related issues

Fixes #9528

Release Summary

setCrashlyticsCollectionEnabled now also passes the value to the native Crashlytics SDK immediately. Firebase guarantees the change from the next app launch, so on iOS a withdrawal no longer waits for the launch after that.

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
    • Other (macOS, web)
  • My change includes tests;
    • e2e tests added or updated in packages/\*\*/e2e
    • jest tests added or updated in packages/\*\*/__tests__
    • Android JVM unit test added in packages/crashlytics/android/src/test
  • I have updated TypeScript types that are affected by my change. (none are affected)
  • This is a breaking change;
    • Yes
    • No

Test Plan

  • Android: ./gradlew :react-native-firebase_crashlytics:compileDebugJavaWithJavac in tests/android builds.
  • iOS: pod install and xcodebuild -workspace testing.xcworkspace -scheme testing -configuration Debug for a simulator build, with RNFBCrashlyticsHelper.o exporting the new setCrashlyticsCollectionEnabled: method.
  • yarn lint:ios:check and google-java-format pass on the changed files; prettier --check passes on the docs page and the types file.
  • jest packages/crashlytics: 28 passed.
  • New NativeRNFBTurboCrashlyticsCollectionEnabledTest (Robolectric, mockStatic like ReactNativeFirebaseCrashlyticsNativeHelperTest): the SDK gets the init provider's value, not the raw argument, so true in a debug build without crashlytics_debug_enabled passes false; plus the enabled and withdrawal cases. With the raw argument passed instead, the debug-build case fails. ./gradlew :react-native-firebase_crashlytics:testDebugUnitTest: 28 passed across the 6 crashlytics JVM test classes.

Nothing changes on the JS side, so there is no new Jest case; the existing e2e tests for setCrashlyticsCollectionEnabled and isCrashlyticsCollectionEnabled still cover the JS flag. The SDK's own collection state is not readable from JS, so e2e cannot observe the native call. The issue reporter verified the same SDK call by hand on both platforms (a crash after withdrawal stays on the device and is deleted).

I used Claude Code to read the code and write the change. I reviewed the diff and ran the builds above myself.

@harpreetkbadhan harpreetkbadhan changed the title fix(crashlytics): apply setCrashlyticsCollectionEnabled in the current run fix(crashlytics): pass setCrashlyticsCollectionEnabled to the native SDK at once Nov 27, 2026

@Mastersam07 Mastersam07 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up so quickly. The native change is what we were after: passing the init provider's computed value keeps the debug-build rule on both platforms. A few changes before this can go in:

1. Don't promise current-run behaviour. The Firebase iOS SDK documents that setCrashlyticsCollectionEnabled: does not apply until the next run of the app (FIRCrashlytics.h), and the Android SDK says the same for false (FirebaseCrashlytics javadoc). The current SDKs may act on it sooner, but we can't promise that on Firebase's behalf. Please reword:

  • The new docs bullet, for example:

    The value is also passed to the native Crashlytics SDK straight away. Firebase guarantees the change from the next app launch, so don't rely on it for crashes later in the same run.

  • The PR title, which becomes the changelog entry, for example: fix(crashlytics): pass setCrashlyticsCollectionEnabled to the native SDK immediately
  • The Release Summary, to match.

2. JSDoc. Please add the same note to setCrashlyticsCollectionEnabled in packages/crashlytics/lib/types/crashlytics.ts. It currently says nothing about when the change takes effect.

3. A unit test is possible on Android. The JVM tests in packages/crashlytics/android/src/test/java/io/invertase/firebase/crashlytics/ already stub the SDK with mockStatic(FirebaseCrashlytics.class); see ReactNativeFirebaseCrashlyticsNativeHelperTest.java for the pattern. Please add a test that the SDK receives the value from ReactNativeFirebaseCrashlyticsInitProvider.isCrashlyticsCollectionEnabled() rather than the raw enabled argument. If the TurboModule is awkward to construct in a test, a small package-private static helper for the new call is fine. Please don't add it to ReactNativeFirebaseCrashlyticsNativeHelper, which is public API for app native code.

@harpreetkbadhan harpreetkbadhan changed the title fix(crashlytics): pass setCrashlyticsCollectionEnabled to the native SDK at once fix(crashlytics): pass setCrashlyticsCollectionEnabled to the native SDK immediately Nov 27, 2026
@harpreetkbadhan

Copy link
Copy Markdown
Author

Thanks @Mastersam07. Done in the latest commit:

  • Docs bullet, title and Release Summary use your wording; nothing promises current-run behaviour any more.
  • The JSDoc for setCrashlyticsCollectionEnabled has the same note.
  • Android: the two steps moved into a package-private static helper, NativeRNFBTurboCrashlytics.saveAndApplyCollectionEnabled, with a JVM test in the mockStatic style of ReactNativeFirebaseCrashlyticsNativeHelperTest. It checks that the SDK gets the init provider's value rather than the argument (true in a debug build without crashlytics_debug_enabled passes false), plus the enabled and withdrawal cases. It fails if the raw argument is passed. ReactNativeFirebaseCrashlyticsNativeHelper is untouched.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[crashlytics] setCrashlyticsCollectionEnabled(false) does not stop the current run; on iOS the change reaches report handling only at the second launch

2 participants