dagger-2

Is there any way of making IntelliJ IDEA recognizing Dagger 2 generated classes in a Java project?

雨燕双飞 提交于 2019-11-27 02:06:37
问题 Context I have started a personal project in java with Gradle as the build system and I want to use Dagger 2 as a DI. The main reason of doing that is to get used to that library and be able to use it easily in bigger projects. What have I tried I've managed to make the Google sample runs on IntelliJ IDEA Problem IntelliJ IDEA keeps telling me that it cannot resolve the generated class (in this case DaggerCoffeeApp_Coffee ). It's a bit annoying not to know if the written code is correct

Android Dagger2 + OkHttp + Retrofit dependency cycle error

旧街凉风 提交于 2019-11-27 01:53:35
问题 Hey there I am using Dagger2 , Retrofit and OkHttp and I am facing dependency cycle issue. When providing OkHttp : @Provides @ApplicationScope OkHttpClient provideOkHttpClient(TokenAuthenticator auth,Dispatcher dispatcher){ return new OkHttpClient.Builder() .connectTimeout(Constants.CONNECT_TIMEOUT, TimeUnit.SECONDS) .readTimeout(Constants.READ_TIMEOUT,TimeUnit.SECONDS) .writeTimeout(Constants.WRITE_TIMEOUT,TimeUnit.SECONDS) .authenticator(auth) .dispatcher(dispatcher) .build(); } When

LiveData is not updating its value after first call

老子叫甜甜 提交于 2019-11-27 01:50:57
问题 I have been beating my head against the wall and I cannot understand why this is happening. I am working with the new Architectural Components for Android and I am having problems updating a LiveData with a List of Objects. I have two spinners. When i change the option in the first one, The second one must have its content changed. But this last part is not happening. Can anyone help me? State.java @Entity(tableName = "states") public class State{ @PrimaryKey(autoGenerate = false) private int

Dagger 2 static provider methods in kotlin

微笑、不失礼 提交于 2019-11-27 01:44:25
问题 With the recent versions of dagger 2 one of the improvements made are the possibility of having static provide methods. Simply so: @Provides static A providesA() { return A(); } I was wondering how does one go about doing this in kotlin? I've tried @Module class AModule { companion object { @JvmStatic @Provides fun providesA(): A = A() } } But I get the error message: @Provides methods can only be present within a @Module or @ProducerModule I'm guessing there's something going on here with

Set dynamic base url using Retrofit 2.0 and Dagger 2

旧城冷巷雨未停 提交于 2019-11-27 00:22:08
I'm trying to perform a login action using Retrofit 2.0 using Dagger 2 Here's how I set up Retrofit dependency @Provides @Singleton Retrofit provideRetrofit(Gson gson, OkHttpClient client) { Retrofit retrofit = new Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create(gson) .client(client) .baseUrl(application.getUrl()) .build(); return retrofit; } Here's the API interface. interface LoginAPI { @GET(relative_path) Call<Boolean> logMe(); } I have three different base urls users can log into. So I can't set a static url while setting up Retrofit dependency. I created a setUrl() and

Can I just inject super class when use dagger2 for dependency injection?

寵の児 提交于 2019-11-27 00:20:40
问题 I use Dagger2 for DI in my android application. I found that I have to write inject method for every class that uses @Inject field. Is there a way that I can just inject the parent class so that I don't have to call inject on every subclass? Take Activity for example. I have a BaseActivity that that every Activity extends from. Is there a way that I can just create an inject method in the component for BaseActivity and just call inject in BaseActivity's onCreate, and @inject fields in sub

How do you organise your Dagger 2 modules and components? [closed]

Deadly 提交于 2019-11-27 00:07:36
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . Do you have a specific package where you put all the Dagger related classes? Or do you put them next to the relevant class they inject, e.g. if you have an MainActivityModule and MainActivityComponent , you put them in the same package as your MainActivity . Also, I've seen

Dagger2 Custom Scopes : How do custom-scopes (@ActivityScope) actually work?

隐身守侯 提交于 2019-11-27 00:06:33
问题 I am reading the source code for Dagger2 Component Scopes Test on GitHub, and I've seen a "custom scope" defined for activities called @ActivityScope , but I've seen it in other projects including the 4-module CleanArchitecture that has its @PerActivity scope. But literally, the code for the @ActivityScope annotation is the following: import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import javax.inject.Scope; /** * Created by joesteele on 2/15/15. */ @Scope

Dagger 2 subcomponents vs component dependencies

╄→尐↘猪︶ㄣ 提交于 2019-11-26 23:27:30
Dagger 1's plus() method is something I used quite often in previous applications, so I understand situations where you might want to have a subcomponent with full access to the parent graphs bindings. In what situation would it be beneficial to use a component dependency instead of a subcomponent dependency and why? Praveer Gupta Component dependencies - Use this when you want to keep two components independent. Subcomponents - Use this when you want to keep two components coupled. I will use the below example to explain Component dependencies and Subcomponents . Some points worth noticing

Error : Program type already present: android.support.design.widget.CoordinatorLayout$Behavior

放肆的年华 提交于 2019-11-26 21:49:03
I am getting the following error while building the project. haven't used CoordinatorLayout in this project. just added as a dependency in build.gradle : I am using Android Studio 3.2 Canary 4. LogCat AGPBI: {"kind":"error","text":"Program type already present: android.support.design.widget.CoordinatorLayout$Behavior","sources":[{}],"tool":"D8"} :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. com.android.builder.dexing