Commit 6ea898d
committed
e2e-app.gradle: upgrade guava dependency to 31.0.1
This fixes a `NoSuchMethodError: No virtual method buildOrThrow()Lcom/google/common/collect/ImmutableMap`
error introduced when the Truth library was upgraded from 1.4.4 to 1.4.5 in PR #7497.
This bug was solved with help from Gemini, which gave this insight:
No, Guava did not remove the method. In fact, the situation is the exact opposite: **buildOrThrow() is a newer method** that was added in Guava **31.0**.
The error NoSuchMethodError is happening because there is a **dependency conflict** in your project.
* **The Cause:** Your test library (Google Truth) was compiled against a **newer** version of Guava (31.0+) and expects buildOrThrow() to exist. However, another library in your project (likely a transitive dependency) is forcing an **older** version of Guava (older than 31.0) onto your classpath at runtime.
* **The Victim:** com.google.common.truth.Subject is trying to call this method, but the older Guava JAR loaded by Android doesn't have it yet.
You need to force your project to use a newer version of Guava that includes this method.
Add (or update) the Guava dependency explicitly in your module's build.gradle file within the dependencies block. Make sure to use the \-android flavor:
Groovy
dependencies {
// Force a newer version of Guava (31.0 or higher) for your tests
androidTestImplementation 'com.google.guava:guava:33.3.1-android'
}
**Note:** If you are using implementation or api for Guava elsewhere, ensure those versions are also consistent (31.0+) so you don't get runtime crashes in your production app as well.
You likely upgraded com.google.truth:truth recently.
* **Truth 1.1.4 and newer** started using ImmutableMap.buildOrThrow() internally.
* If your project pulls in an older library (like an older version of the Android tools or Firebase SDKs) that depends on Guava 28.x or 20.0, Gradle's conflict resolution might be downgrading Guava to that older version, breaking Truth.
To confirm which old library is "poisoning" your dependency tree, you can run the following command in your terminal:
Bash
./gradlew app:dependencies \--configuration androidTestCompileClasspath
*(Replace app with your module name)*. Look for com.google.guava:guava in the output. You will likely see something like 33.3.1-android \-\> 28.1-android, indicating a downgrade happened. Adding the explicit dependency above fixes this by telling Gradle "I really mean it, use the new one."1 parent 880bfc3 commit 6ea898d
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
0 commit comments