Skip to content

Conversation

@avazirna
Copy link
Contributor

@avazirna avazirna commented Jul 3, 2025

Product Description

Developers have reported crashes in debug mode after enabling Firebase Perf monitoring. The stack trace is:

java.lang.IllegalArgumentException: Please set a valid API key. A Firebase API key is required to communicate with Firebase server APIs: It authenticates your project with Google.Please refer to https://firebase.google.com/support/privacy/init-options.
                 	at com.google.android.gms.common.internal.Preconditions.checkNotEmpty(com.google.android.gms:play-services-basement@@18.3.0:4)
                 	at com.google.firebase.installations.FirebaseInstallations.preConditionChecks(FirebaseInstallations.java:175)
                 	at com.google.firebase.installations.FirebaseInstallations.getId(FirebaseInstallations.java:235)
                 	at com.google.firebase.perf.transport.TransportManager.updateFirebaseInstallationIdIfPossibleAndNeeded(TransportManager.java:566)
                 	at com.google.firebase.perf.transport.TransportManager.setApplicationInfoAndBuild(TransportManager.java:502)
                 	at com.google.firebase.perf.transport.TransportManager.syncLog(TransportManager.java:379)
                 	at com.google.firebase.perf.transport.TransportManager.lambda$log$2$com-google-firebase-perf-transport-TransportManager(TransportManager.java:301)
                 	at com.google.firebase.perf.transport.TransportManager$$ExternalSyntheticLambda0.run(Unknown Source:6)
                 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                 	at java.lang.Thread.run(Thread.java:1012)

Technical summary

Firebase Perf monitoring is disabled by default and enabled when in Release mode. This PR also removes duplicate dependency entries from the Gradle build configuration.

Safety Assurance

Safety story

Automated test coverage

Labels and Review

  • Do we need to enhance the manual QA test coverage ? If yes, the "QA Note" label is set correctly
  • Does the PR introduce any major changes worth communicating ? If yes, the "Release Note" label is set and a "Release Note" is specified in PR description.
  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@coderabbitai
Copy link

coderabbitai bot commented Jul 3, 2025

📝 Walkthrough

Walkthrough

This change removes outdated dependencies from the app/build.gradle file, specifically older versions of the org.json:json and Firebase Crashlytics libraries, retaining only their newer versions. Additionally, it updates the CommCareApplication class to disable Firebase Performance Monitoring when the app is built in debug mode by adding a conditional check in the onCreate() method. No public APIs or exported entities are altered.

Sequence Diagram(s)

sequenceDiagram
    participant App as CommCareApplication
    participant BuildConfig
    participant FirebasePerf as FirebasePerformance

    App->BuildConfig: Check DEBUG flag
    alt If DEBUG is true
        App->FirebasePerf: getInstance()
        App->FirebasePerf: setPerformanceCollectionEnabled(false)
    end
    App->App: Continue normal initialization
Loading

Possibly related PRs

  • - removed duplicate dependencies #3115: Both PRs focus on removing redundant or duplicate dependency declarations in the app/build.gradle file, addressing similar maintenance concerns in dependency management.
  • Update Firebase dependencies #3002: The main PR removes older Firebase Crashlytics dependency versions, while the retrieved PR updates Firebase dependencies including Crashlytics to newer versions; both modify Firebase dependency versions in app/build.gradle, making them related.

Suggested labels

product/invisible

Suggested reviewers

  • shubham1g5
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in a Comment
  • Commit Unit Tests in branch disabled-firebase-perf-monitoring-on-debug-mode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/src/org/commcare/CommCareApplication.java (1)

39-39: Missing Gradle/Manifest guard – import alone won’t prevent early perf init

Adding the FirebasePerformance import is harmless, but note that the Perf SDK is still auto-initialized by FirebaseInitProvider before Application.onCreate(). If the root cause of the crash is that this auto-init runs in debug builds with an invalid API-key, the new runtime flag below may run too late. Consider additionally disabling the Perf component for debug via

debugImplementation (platform("com.google.firebase:firebase-bom:…")) {
    exclude group: "com.google.firebase", module: "firebase-perf"
}

or by putting

<meta-data android:name="firebase_performance_collection_enabled" android:value="false"/>

in the debug manifest to stop the component from starting at all.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb95365 and 245b5e1.

📒 Files selected for processing (2)
  • app/build.gradle (0 hunks)
  • app/src/org/commcare/CommCareApplication.java (2 hunks)
💤 Files with no reviewable changes (1)
  • app/build.gradle
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: OrangeAndGreen
PR: dimagi/commcare-android#2912
File: app/src/org/commcare/fragments/connect/ConnectPaymentSetupFragment.java:61-66
Timestamp: 2025-01-21T17:29:58.014Z
Learning: In the CommCare Android app, for non-critical convenience features like phone number auto-population, exceptions should be logged but fail silently when there's a manual fallback available. This approach prevents app crashes while maintaining the ability to debug issues through logs.
Learnt from: Jignesh-dimagi
PR: dimagi/commcare-android#3070
File: app/res/values/themes.xml:80-80
Timestamp: 2025-05-07T06:48:32.621Z
Learning: The CommCare Android app doesn't require backward compatibility for support library features like the vector drawable compatibility provided by app:srcCompat. It uses android:src directly for drawable references in themes.
Learnt from: Jignesh-dimagi
PR: dimagi/commcare-android#3093
File: app/res/layout/view_country_code_edittext.xml:2-7
Timestamp: 2025-05-09T06:50:50.863Z
Learning: The CommCare Android app uses minSdkVersion 21 (Android 5.0 Lollipop), so API 21+ attributes like paddingVertical and paddingHorizontal can be used without compatibility concerns.
Learnt from: pm-dimagi
PR: dimagi/commcare-android#2847
File: app/build.gradle:294-295
Timestamp: 2025-01-27T15:18:25.903Z
Learning: The Connect base URL and API version in build.gradle are intentionally hardcoded as these values do not change with variants.
app/src/org/commcare/CommCareApplication.java (10)
Learnt from: pm-dimagi
PR: dimagi/commcare-android#2847
File: app/src/org/commcare/utils/EncryptionUtils.java:167-167
Timestamp: 2025-01-27T15:14:56.422Z
Learning: MD5 hashing is acceptable for non-security purposes like analytics tracking in FirebaseAnalyticsUtil.
Learnt from: OrangeAndGreen
PR: dimagi/commcare-android#3121
File: app/src/org/commcare/activities/CommCareSetupActivity.java:360-364
Timestamp: 2025-05-22T14:28:35.959Z
Learning: In CommCareSetupActivity.java, the call to installFragment.showConnectErrorMessage() after fragment transactions is intentionally unguarded with null checks. This follows the app's design pattern where critical error paths prefer immediate crashes over silent failures, making potential issues immediately visible during development rather than hiding them with defensive programming.
Learnt from: OrangeAndGreen
PR: dimagi/commcare-android#2912
File: app/src/org/commcare/fragments/connect/ConnectPaymentSetupFragment.java:61-66
Timestamp: 2025-01-21T17:29:58.014Z
Learning: In the CommCare Android app, for non-critical convenience features like phone number auto-population, exceptions should be logged but fail silently when there's a manual fallback available. This approach prevents app crashes while maintaining the ability to debug issues through logs.
Learnt from: OrangeAndGreen
PR: dimagi/commcare-android#3108
File: app/src/org/commcare/fragments/connect/ConnectJobIntroFragment.java:65-71
Timestamp: 2025-06-06T20:15:21.134Z
Learning: In the CommCare Android Connect module, job.getLearnAppInfo() and getLearnModules() should never return null according to the system design. The team prefers to let the code crash if these values are unexpectedly null rather than adding defensive null checks, following a fail-fast philosophy to catch bugs early rather than masking them.
Learnt from: Jignesh-dimagi
PR: dimagi/commcare-android#3093
File: app/res/layout/view_country_code_edittext.xml:2-7
Timestamp: 2025-05-09T06:50:50.863Z
Learning: The CommCare Android app uses minSdkVersion 21 (Android 5.0 Lollipop), so API 21+ attributes like paddingVertical and paddingHorizontal can be used without compatibility concerns.
Learnt from: shubham1g5
PR: dimagi/commcare-android#3116
File: app/src/org/commcare/fragments/connectId/PersonalIdPhotoCaptureFragment.java:0-0
Timestamp: 2025-05-19T15:36:34.511Z
Learning: In the CommCare Android codebase, a "fail fast" approach is preferred for internal encoding/decoding operations where both sides are controlled by the application. This helps surface bugs immediately rather than masking them with graceful error handling.
Learnt from: OrangeAndGreen
PR: dimagi/commcare-android#3121
File: app/src/org/commcare/fragments/SelectInstallModeFragment.java:201-205
Timestamp: 2025-05-22T14:26:41.341Z
Learning: In SelectInstallModeFragment.java, the showConnectErrorMessage method intentionally omits null checks because it's called at a specific point in the startup flow where UI is guaranteed to be loaded. It's designed to crash if activity or view is null to make potential issues immediately visible rather than hiding them with defensive programming.
Learnt from: OrangeAndGreen
PR: dimagi/commcare-android#2912
File: app/src/org/commcare/android/database/connect/models/ConnectUserRecord.java:81-89
Timestamp: 2025-01-21T17:27:58.754Z
Learning: In the CommCare Android codebase, use org.jetbrains.annotations.NotNull for null-safety annotations. Empty strings are acceptable for unspecified values, but null values should be prevented using @NotNull.
Learnt from: avazirna
PR: dimagi/commcare-android#3057
File: app/src/org/commcare/views/widgets/AudioRecordingService.java:105-138
Timestamp: 2025-05-01T10:50:29.135Z
Learning: In the CommCare Android app, IllegalStateException from MediaRecorder operations should not be caught to ensure visibility of recording setup issues through app crashes.
Learnt from: OrangeAndGreen
PR: dimagi/commcare-android#3108
File: app/src/org/commcare/fragments/connect/ConnectDeliveryDetailsFragment.java:163-180
Timestamp: 2025-06-06T19:52:53.173Z
Learning: In the CommCare Android Connect feature, database operations like ConnectJobUtils.upsertJob should be allowed to crash rather than being wrapped in try-catch blocks. The team prefers fail-fast behavior for database errors instead of graceful error handling.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint Code Base

Comment on lines 222 to 224
if (BuildConfig.DEBUG) {
FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false);
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Runtime flag may still trigger the same crash

FirebasePerformance.getInstance() itself performs substantial setup (including a FIS call) and can throw the same IllegalArgumentException the PR is trying to avoid. Wrapping the call in a try/catch keeps the debug build crash-free even if auto-init already failed, while still disabling collection when it succeeds:

-if (BuildConfig.DEBUG) {
-    FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false);
-}
+if (BuildConfig.DEBUG) {
+    try {
+        FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false);
+    } catch (IllegalStateException | IllegalArgumentException e) {
+        Log.w(TAG, "Firebase Perf disabled – init failed in debug build", e);
+    }
+}

This keeps fail-fast behaviour in release, yet prevents dev crashes.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (BuildConfig.DEBUG) {
FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false);
}
if (BuildConfig.DEBUG) {
try {
FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false);
} catch (IllegalStateException | IllegalArgumentException e) {
Log.w(TAG, "Firebase Perf disabled – init failed in debug build", e);
}
}
🤖 Prompt for AI Agents
In app/src/org/commcare/CommCareApplication.java around lines 222 to 224, the
call to FirebasePerformance.getInstance() can throw an IllegalArgumentException
even in debug builds, causing crashes. To fix this, wrap the call to
FirebasePerformance.getInstance().setPerformanceCollectionEnabled(false) in a
try/catch block that catches IllegalArgumentException, so the debug build does
not crash if initialization fails, while still disabling performance collection
when possible.

@avazirna
Copy link
Contributor Author

avazirna commented Jul 4, 2025

@damagatchi retest this please

@avazirna avazirna force-pushed the disabled-firebase-perf-monitoring-on-debug-mode branch from 245b5e1 to 3890a12 Compare July 7, 2025 21:51
@avazirna avazirna requested a review from shubham1g5 July 8, 2025 08:06
implementation 'com.journeyapps:zxing-android-embedded:3.6.0'
implementation 'com.google.firebase:firebase-analytics:20.1.2'
implementation 'com.google.firebase:firebase-messaging:21.1.0'
implementation 'com.google.firebase:firebase-crashlytics:17.2.1'
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we explain this in context of PR ?

@avazirna avazirna requested a review from shubham1g5 July 9, 2025 14:58
@avazirna avazirna merged commit 964109a into master Jul 16, 2025
6 of 9 checks passed
@avazirna avazirna deleted the disabled-firebase-perf-monitoring-on-debug-mode branch July 16, 2025 12:06
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.

3 participants