firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.26k stars 571 forks source link

Firebase Crashlytics uses Dagger 2 while my project uses Dagger 1 #1643

Closed kaciula closed 4 years ago

kaciula commented 4 years ago

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Adding the dependency for the new Firebase Crashlytics makes my project not build anymore because I am using Dagger1 everywhere in my code and it seems Crashlytics uses Dagger 2.

Seeing that there are big projects still using Dagger 1 and migrating to Dagger 2 is impossible for the foreseeable future, I am hoping there is a way for the Firebase SDK to work also with Dagger 1 projects.

Please provide some guidance on this issue. Either have the firebase sdks relocate Dagger 2 packages or provide a solution for clients of the SDK to have both Dagger 1 and Dagger 2 in their projects.

Thanks.

google-oss-bot commented 4 years ago

I found a few problems with this issue:

ashwinraghav commented 4 years ago

Thanks for the report. I recognize the challenge of running into this while migrating from Fabric. Unfortunately, dagger 2 is the standard across a variety of Firebase products that are ubiquitous across Android apps - In App Messaging, Crashlytics, Firebase Messaging.

It is a challenge deciding what versions of dependencies Firebase SDKs can have. On the one hand we have to think of what version most of our customers use, while also considering how we can continue supporting customers who want the latest and greatest. At times, this forces us to not use any libraries in our products and write things ground up.

We decided to roll forward with Dagger2 a while back, since Dagger1 has been deprecated for a while, and the performance benefits it offers to us and Firebase customers makes this worthwhile.

Work around

I've not tried this myself. But I can imagine how this would work if you wanted to incrementally migrate off of Dagger 1 to Dagger 2 while continuing to use Firebase.

  1. Consider using the excellent com.github.johnrengelman.shadow shadow plugin to repackage dagger to (say) firebase.dagger.
plugins {
    id 'com.github.johnrengelman.shadow' version '5.2.0'
    id 'java'
}

shadowJar {
    relocate 'javax.inject.Inject', 'javax.inject.Inject2'
    relocate 'javax.inject.Named', 'javax.inject.Named2'
    relocate 'javax.inject.Provider', 'javax.inject.Provider2'
    relocate 'javax.inject.Qualifier', 'javax.inject.Qualifier2'
    relocate 'javax.inject.Scope', 'javax.inject.Scope2'
    relocate 'javax.inject.Singleton', 'javax.inject.Singleton2'
    relocate 'dagger.Lazy', 'dagger.Lazy2'
    relocate 'dagger.MembersInjector', 'dagger.MembersInjector2'
    relocate 'dagger.Module', 'dagger.Module2'
    relocate 'dagger.Provides', 'dagger.Provides2'
    relocate 'dagger.Provides$Type', 'dagger.Provides$Type2'
    relocate 'dagger.internal', 'dagger.internal2'
    relocate 'dagger.producers', 'dagger.producers2'
}
  1. By default, the plugin also migrates any imports in third party dependencies, which would automatically replace any references to dagger in crashlytics.

I realize that is not all working code. But, that's the best I got, given our official position. Please write back if that works out for you, so we can continue referencing this issue for others that may face the problem. Thanks!

References
Dagger 1 and 2 together
Migrating to dagger 2incrementally
Shadow Plugin
Sample project