I do a test project using Dagger2 . I get the error

Error: Execution failed for task ': app: compileDebugJavaWithJavac'. java.lang. NoSuchMethodError: com.google.common.collect.ImmutableSetMultimap $ Builder.putAll (Ljava / lang / Iterable;) Lcom / google / common / collect / ImmutableSetMultimap $ Builder;

I can not understand what's wrong. The search for a solution so far has not been successful.

Here is the project code:

App:

 public class App extends Application { private static AppComponent component; public static AppComponent getComponent() { return component; } @Override public void onCreate() { super.onCreate(); component = buildComponent(); } protected AppComponent buildComponent() { return DaggerAppComponent.builder() .build(); } } 

AppComponent:

 @Singleton @Component(modules = {NetWorkApiModule.class}) public interface AppComponent { void inject(MainActivity mainActivity); } 

NetWorkApiModule:

 @Module public class NetWorkApiModule { @Provides @Singleton public NetWorkApi getNetwork(){ return new NetWorkApi(); } } 

MainActivity:

 public class MainActivity extends AppCompatActivity { @Inject NetWorkApi mNetWorkApi; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); App.getComponent().inject(this); boolean injected = mNetWorkApi != null; ((TextView)findViewById(R.id.text)).setText(String.valueOf(injected)); } } 
  • one
    They write that you can roll back to dagger 2.2 - zRrr

1 answer 1

Copied all your code, everything works. In gradle project

  // Assists in working with annotation processors for Android Studio. classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4' 

in gradle app

 // Dagger 2 and Compiler compile 'com.google.dagger:dagger:2.0.1' apt "com.google.dagger:dagger-compiler:2.0.1" //Needed for @Generated annotation (missing in Android API jar) // No longer needed in dagger >= 2.1-SNAPSHOT (github.com/google/dagger/issues/95) compile 'javax.annotation:jsr250-api:1.0' // Assists in working with annotation processors for Android Studio. apply plugin: 'com.neenbedankt.android-apt' 
  • Thanks for the help. I had provided 'org.glassfish: javax.annotation: 10.0-b28' set compile 'javax.annotation: jsr250-api: 1.0' and it all worked. - marazmone