Android X + Truth + Guava test compile issue

I have an Android library (called&nbsp;<code>api</code>) gradle module as part of a larger project. I just migrated the whole project to AndroidX. I now have this error when running instrumentation test on the&nbsp;<code>api</code>&nbsp;lib:

I have an Android library (called api) gradle module as part of a larger project. I just migrated the whole project to AndroidX. I now have this error when running instrumentation test on the api lib:

 Task :api:checkDebugAndroidTestDuplicateClasses FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':api:checkDebugAndroidTestDuplicateClasses'.
    > 1 exception was raised by workers:
    java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules jetified-guava-25.1-android.jar (com.google.guava:guava:25.1-android) and listenablefuture-1.0.jar (com.google.guava:listenablefuture:1.0)

If I check the runtime class path for the debugAndroidTest variant:

./gradlew api:dependencies --configuration debugAndroidTestRuntimeClasspath | grep --color -E "guava|$"

I get this output. I can see the problem:

------------------------------------------------------------
Project :api

debugAndroidTestRuntimeClasspath - Resolved configuration for runtime for variant: debugAndroidTest
+--- project :test_utils
| +--- project :core
...
| +--- project :api ()
| +--- com.google.android.material:material:1.1.0-alpha03
| | +--- androidx.annotation:annotation:1.0.1 -> 1.1.0-alpha01
| | +--- androidx.appcompat:appcompat:1.1.0-alpha01
| | | +--- androidx.annotation:annotation:1.0.0 -> 1.1.0-alpha01
| | | +--- androidx.core:core:1.1.0-alpha01 -> 1.1.0-alpha03
| | | | +--- com.google.guava:listenablefuture:1.0 // <------ GUAVA
| | | | +--- androidx.annotation:annotation:1.0.1 -> 1.1.0-alpha01
...
+--- com.google.truth:truth:0.42
| +--- com.google.guava:guava:25.1-android / <------ MORE GUAVA
| | +--- com.google.code.findbugs:jsr305:3.0.2
| | +--- com.google.errorprone:error_prone_annotations:2.1.3 -> 2.3.1
| | +--- com.google.j2objc:j2objc-annotations:1.1
| | --- org.codehaus.mojo:animal-sniffer-annotations:1.14
| +--- org.checkerframework:checker-compat-qual:2.5.3
| +--- org.checkerframework:checker-qual:2.5.3
| +--- junit:junit:4.12 (
)
| +--- com.googlecode.java-diff-utils:diffutils:1.3.0
| +--- com.google.auto.value:auto-value-annotations:1.6.2
| --- com.google.errorprone:error_prone_annotations:2.3.1
...

AndroidX core is depending on the new "ListableFuture-only" build of guava and Truth is depending on the full Guava 25.

I think I understand the underlying problem with ListenableFuture: https://groups.google.com/forum/#!topic/guava-announce/Km82fZG68Sw

What is the right solution here?

I don't want to exclude Guava from Truth entirely (otherwise Truth won't compile)

androidTestImplementation("com.google.truth:truth:0.42") {
exclude group: 'com.google.guava', module: 'guava'
}

Can I exclude + force update to Guava 27 by making it a first-level dependency:

androidTestImplementation("com.google.truth:truth:$rootProject.ext.truthVersion") {
exclude group: 'com.google.guava', module: 'guava'
}
// must add guava as top level dependency to force Truth to use latest version
androidTestImplementation 'com.google.guava:guava:27.0.1-android'

If I do this, should I be using the android or JRE version of guava?

Side question:

Why don't I see the guava dependency when looking at compile classpath? The error is a compile time error, not a runtime error

./gradlew api:dependencies --configuration debugAndroidTestCompileClasspath | grep --color -E "guava|$"

Resulting deps:

debugAndroidTestCompileClasspath - Resolved configuration for compilation for variant: debugAndroidTest
+--- project :test_utils // <----------- why are test_utils deps not listed here???
...
+--- com.google.truth:truth:0.42
| +--- com.google.guava:guava:25.1-android <------ GUAVA
| | +--- com.google.code.findbugs:jsr305:3.0.2
| | +--- org.checkerframework:checker-compat-qual:2.0.0 -> 2.5.3
| | +--- com.google.errorprone:error_prone_annotations:2.1.3 -> 2.3.1
| | +--- com.google.j2objc:j2objc-annotations:1.1
| | --- org.codehaus.mojo:animal-sniffer-annotations:1.14
| +--- org.checkerframework:checker-compat-qual:2.5.3
| +--- org.checkerframework:checker-qual:2.5.3
| +--- junit:junit:4.12 (*)
| +--- com.googlecode.java-diff-utils:diffutils:1.3.0
| +--- com.google.auto.value:auto-value-annotations:1.6.2
| --- com.google.errorprone:error_prone_annotations:2.3.1
...
+--- com.google.truth:truth:{strictly 0.42} -> 0.42 (c)
+--- com.google.guava:guava:{strictly 25.1-android} -> 25.1-android (c) // <--------- why is this listed again here at top level?


Kotlin Coroutines on Android - How to use Coroutines on Android

Kotlin Coroutines on Android - How to use Coroutines on Android

Coroutines are a Kotlin feature that convert async callbacks for long-running tasks, such as database or network access, into sequential code. This Kotlin Coroutines tutorial will show you how to use coroutines on Android, and how the new androidx-concurrent library makes it easy to use them to get things off the main thread. You'll also learn how the new library helps coroutines work with Architecture Components. This session also covers coroutine patterns, best practices, and even how to test coroutines!

Kotlin Coroutines on Android - How to use Coroutines on Android.

Coroutines are a feature of Kotlin that help convert callback-based code into sequential code, making code easier to read, write, and understand. This session will show you how to use coroutines on Android, and how the new androidx-concurrent library makes it easy to use them to get things off the main thread. You'll also learn how the new library helps coroutines work with Architecture Components. This session also covers coroutine patterns, best practices, and even how to test coroutines!

Android App Development Services Agency in New York

Android App Development Services Agency in New York

Looking for a well-renowned [Android App Development Service Agency in New York]**(https://www.appcluesinfotech.com/android-app-deve**lopment-company/ "Android App Development Service Agency in New York")? AppClues Infotech is the most reliable &...

Looking for a well-renowned Android App Development Service Agency in New York? AppClues Infotech is the most reliable & trustworthy Android App Development Services Agency in New York. We have a dedicated team of developers who can create custom Android mobile applications for start-ups as well as enterprises.

We believed to be one of the most popular service providers of Android app development. The Team has high knowledge and the best strength of developing any type of Android mobile apps. We offer versatile Android App development technology solutions to their clients at an affordable price.

Our Android App Development Service:
• Android App UX / UI Design
• Native App Development
• Android App Programming
• App Redesigning
• App Testing for flawless Performance
• App Support & Maintenance

For more info:
Visit: https://www.appcluesinfotech.com/
Email: [email protected]
Call: +1-978-309-9910

Leading Android App Development Agency in New York

Leading Android App Development Agency in New York

AppClues Infotech as one of the [Leading Android App Development Agency in New York]**(https://www.appcluesinfotech.com/android-app-deve**lopment-company/ "Leading Android App Development Agency in New York") one thing that separates our team of...

AppClues Infotech as one of the Leading Android App Development Agency in New York one thing that separates our team of app design & development experts from the competition comes down to the timely manner that we are able to get a functional Android mobile app developed.

Amongst the Android mobile application development companies, AppClues Infotech is the most foremost Android app development company that builds modified, resourceful and creative apps. Our Team has high knowledge and the greatest strength of developing any type of Android mobile apps.

Our Android App Development Service:
• Android App UX / UI Design
• Native App Development
• Android App Programming
• App Redesigning
• App Testing for flawless Performance
• App Support & Maintenance

For more info:
Visit: https://www.appcluesinfotech.com/
Email: [email protected]
Call: +1-978-309-9910