Supporting a Dagger 2 dependency in a Dagger 1 project

我的未来我决定 提交于 2020-02-25 02:10:11

问题


This is a follow-up to my question about Play Services Cast Framework, where the solution seems to be updating from v17.0.0 to v18.0.0. The new version unfortunately has a dependency on Dagger 2, whilst the (large & complex) project is Dagger 1.

We are currently using:

api "com.google.android.gms:play-services-cast:17.0.0"
api "com.google.android.gms:play-services-cast-framework:17.0.0"

Updating these to 18.0.0 results in:

> 1 exception was raised by workers:
java.lang.RuntimeException: Duplicate class dagger.Lazy found in modules dagger-1.2.2.jar (com.squareup.dagger:dagger:1.2.2) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class dagger.MembersInjector found in modules dagger-1.2.2.jar (com.squareup.dagger:dagger:1.2.2) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class dagger.Module found in modules dagger-1.2.2.jar (com.squareup.dagger:dagger:1.2.2) and dagger-2.22.jar (com.google.dagger:dagger:2.22)
Duplicate class dagger.Provides found in modules dagger-1.2.2.jar (com.squareup.dagger:dagger:1.2.2) and dagger-2.22.jar (com.google.dagger:dagger:2.22)

Ideally I'd be able to let the new version of the library use Dagger 2 whilst the rest of the app uses Dagger 1. Reworking the project to use Dagger 2 is a multi-week undertaking.

Any ideas?


What I've tried already:

Excluding Dagger 2 from the cast framework via:

api("com.google.android.gms:play-services-cast:18.0.0") {
    exclude group:'com.google.dagger', module:'dagger'
}
api("com.google.android.gms:play-services-cast-framework:18.0.0") {
    exclude group:'com.google.dagger', module:'dagger'
}

unsurprisingly resulted in:

   java.lang.NoClassDefFoundError: Failed resolution of: Ldagger/internal/Preconditions;
        at com.google.android.datatransport.runtime.DaggerTransportRuntimeComponent$Builder.setApplicationContext(com.google.android.datatransport:transport-runtime@@2.1.0:150)

Forcing the cast framework to use an older version via the following also resulted in duplicate classes:

configurations.all {
    resolutionStrategy {
        preferProjectModules()
        dependencySubstitution {
            substitute(module("com.google.dagger:dagger:2.22")).with(module("com.squareup.dagger:dagger:1.2.2"))
        }
    }
}

Potentially related questions that didn't help:

  • Dagger 2 application using library that uses dagger 1 - No answers / comments.
  • Dagger 1 and Dagger 2 package names conflict - Seems to be a different issue further down the line.
  • How do I make Dagger 1 and Dagger 2 coexist together in one Android project? To do with migration, not resolving dependency in third party library.

来源:https://stackoverflow.com/questions/60267351/supporting-a-dagger-2-dependency-in-a-dagger-1-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!