firebase / firebase/firebase-android-sdk

NoSuchMethodError: DesugarCollections.synchronizedMap in release instrumentation tests with firebase-sessions 3.0.7 (BOM 34.x)

Open
#8,600 0 comments 0 reactions 0 assignees View on GitHub
api: sessions
Dominant language
Java
Stars
2.6k
Forks
710
Avg merge
2d 23h
Merged PRs (30d)
34

Description

Running Instrumentation tests with minify enabled release builds after updating to the 34.x from 33.x results into a `NoSuchMethodError` crash as soon as we launch the app in test environment.

### Environment

- Firebase BOM: 34.18.0
- firebase-sessions: 3.0.7
- firebase-crashlytics: 20.1.1
- AGP: 8.13.2
- desugar_jdk_libs: 2.1.5 (latest public)
- testBuildType: release
- minifyEnabled: true

#### Steps to reproduce:

1. Add firebase-crashlytics (or any lib that pulls in firebase-sessions) with BOM 34.x
2. Set minifyEnabled true in release build type
3. Set testBuildType "release" in android block
4. Set coreLibraryDesugaringEnabled true with desugar_jdk_libs:2.1.5
5. Run adb shell am instrument -w -r .test/androidx.test.runner.AndroidJUnitRunner

Expected: instrumentation test runs
Actual: process crashes immediately during FirebaseInitProvider.onCreate before any test runs -

````
java.lang.NoSuchMethodError: No static method synchronizedMap(Ljava/util/Map;)Ljava/util/Map;
in class Lj$/util/DesugarCollections; or its super classes
(declaration of 'j$.util.DesugarCollections' appears in .test apk)
at CrashlyticsRegistrar.
at FirebaseInitProvider.onCreate
````

firebase-sessions:3.0.7 calls `DesugarCollections.synchronizedMap()` which was compiled against an internal desugaring library that includes this method. In a normal release build this works because Firebase's bundled DesugarCollections (with synchronizedMap) is the only one present. In release instrumentation tests, the test APK brings its own DesugarCollections from the public desugar_jdk_libs:2.1.5 (which lacks synchronizedMap) and it shadows the main APK's version, causing the crash.

#### Relevant Code:

Attaching a minimal repro project to reproduce this issue.

[firebase-desugar-repro.zip](https://github.com/user-attachments/files/32227844/firebase-desugar-repro.zip)

Contributor guide

Open the contributing guide

Research direction

Start with the attached firebase-desugar-repro.zip and reproduce the crash using the listed release instrumentation-test configuration and adb command. Trace the conflicting DesugarCollections versions between the main and test APKs; done means the release instrumentation test launches without the NoSuchMethodError.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, firebase, java
Domain
build-system, mobile, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.