Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate class in modules dagger-1.2.2.jar and dagger-2.22.jar

After upgrading all libraries to androidx and to the latest versions of Firebase libraries

I got error with 2 different versions of dagger java files, link in the error message doesn't work. Problem occurs at step :app:checkDebugDuplicateClasses.

I do not use dagger directly in my code, using

./gradlew app:dependencies

I found what com.google.android.gms:play-services-cast-framework:17.1.0 uses com.google.dagger:dagger:2.22, but no info about 1.2.2.

Cause 1: java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class dagger.Lazy found in modules dagger-1.2.2.jar (dagger-1.2.2.jar) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class dagger.MembersInjector found in modules dagger-1.2.2.jar (dagger-1.2.2.jar) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class dagger.Module found in modules dagger-1.2.2.jar (dagger-1.2.2.jar) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class dagger.Provides found in modules dagger-1.2.2.jar (dagger-1.2.2.jar) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class javax.inject.Inject found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Duplicate class javax.inject.Named found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Duplicate class javax.inject.Provider found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Duplicate class javax.inject.Qualifier found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Duplicate class javax.inject.Scope found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)
Duplicate class javax.inject.Singleton found in modules javax.inject-1.jar (javax.inject-1.jar) and javax.inject-1.jar (javax.inject:javax.inject:1)

Go to the documentation to learn how to Fix dependency resolution errors.
like image 878
Anton Avatar asked Sep 29 '19 14:09

Anton


1 Answers

The easiest way is to analyze dependencies.

SOLUTION #1 (console only)

Run in console:

./gradlew -q dependencies app:dependencies

enter image description here

After receiving list of dependencies in the console, go to Analyze part (below Solution #2).


SOLUTION #2 (generate html)

1) Add plugin to generate report

In to app/build.gradle (this with compileSdkVersion, targetSdkVersion or buildTypes), at the top add:

apply plugin: 'project-report'

near one of them:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

which are on top.

2) Generate report

Just from the console run:

 ./gradlew htmlDependencyReport

or from Android Studio

Tasks > other > htmlDependencyReport

enter image description here

3) Open report

In console you will find URL:

./gradlew htmlDependencyReport


> Task :app:htmlDependencyReport
See the report at: file:///Users/user_name/your_path/project_name/app/build/reports/project/dependencies/index.html

And go to the project ':app'

enter image description here

4) Analyze report

After clicking each of the position there are dependencies: enter image description here

To expand all of them, you can in develper console such code:

$('#dependencies').html(function(index, html) {
    return html.split('style="display: none;"')
               .join('style="display: block;"')
               .split('<h3 class="closed">')
               .join('<h3>')
});

ANALYZE

1) Find old dependencies

In your case you are searching phrase dagger:1

enter image description here

Or in the console:

enter image description here

2) Exlude dependencies

Find in the report library name, and just exclude group from this import.

In your build.gradle (where you have all of dependencies) modify "problematic" library excluding dagger v1.

For example:

implementation("some.old.library.using.dagger1:1.0.0") {
    exclude group: 'com.squareup.dagger', module: 'dagger'
}
like image 68
Boken Avatar answered Oct 14 '22 03:10

Boken