3

I'm getting the next crash when I launch my Android app after adding the first Dagger module.

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/collect/ImmutableMap;
    at com.sofaking.moonworshipper.DaggerAppComponent.getMapOfClassOfAndProviderOfFactoryOf(DaggerAppComponent.java:35)
    at com.sofaking.moonworshipper.DaggerAppComponent.getDispatchingAndroidInjectorOfActivity(DaggerAppComponent.java:41)
    at com.sofaking.moonworshipper.DaggerAppComponent.injectApp(DaggerAppComponent.java:64)
    at com.sofaking.moonworshipper.DaggerAppComponent.inject(DaggerAppComponent.java:59)
    at com.sofaking.moonworshipper.DaggerAppComponent.inject(DaggerAppComponent.java:16)

The issue seems to be identical to this one on GitHub: https://github.com/google/dagger/issues/897

I understand that Dagger is trying to use Guava, although it shouldn't - But I'm not sure what to do to fix this. It's not a proguard issue.

I tried to include guava in my dependencies - which presented the next error while compiling:

Error: Program type already present: com.google.common.util.concurrent.internal.InternalFutures

which makes sense, as there are other libraries in my code which depend on guava.

implementation 'com.google.dagger:dagger:2.15'
kapt 'com.google.dagger:dagger-compiler:2.15'

compile 'com.google.dagger:dagger-android:2.15'
compile 'com.google.dagger:dagger-android-support:2.15'
kapt 'com.google.dagger:dagger-android-processor:2.15'

// tried adding this as well, didn't work
api 'com.google.guava:guava:27.0-android'

Edit: Here's tree of resolved dependecies: https://pastebin.com/RsPPjD6H

dasfima
  • 4,841
  • 3
  • 21
  • 24
  • Do you have a dependency which uses `compileOnly` or `provided`? – Zun Nov 13 '18 at 13:49
  • no `provided` dependencies, only one `compileOnly` dependency. Should that a problem? – dasfima Nov 13 '18 at 13:55
  • 1
    Can you post a tree of resolved dependencies? Also, mind that [since Guava 27.0 there's a separate artifact for `ListenableFuture`](https://stackoverflow.com/questions/52979664/how-to-remedy-error-caused-by-guava-program-type-already-present-com-google-co). – Grzegorz Rożniecki Nov 13 '18 at 15:05
  • @Xaerxess I just did. Please have a look if you can. – dasfima Nov 14 '18 at 01:18

2 Answers2

2

After seeing that Dagger depends on com.google.guava:guava:23.3-jre, I tried adding the next line in my Gradle build file:

api 'com.google.guava:guava:23.3-android'

And it works!

dasfima
  • 4,841
  • 3
  • 21
  • 24
0

The word "compile" is not used anymore. Use "implementation" instead in your dependencies. I don't know if that is causing the issue but maybe.

Lenin
  • 500
  • 3
  • 11
  • Just tried that. Didn't help. replaces all the `compile` with `implementation` - except for `compileOnly`, which seems to be the updated one. – dasfima Nov 13 '18 at 13:56