dagger-2

Dagger 2 cannot access Retrofit

天大地大妈咪最大 提交于 2020-04-08 09:05:21
问题 I'm trying to provide an instance of Retrofit to my Repository using Dagger 2 (with Android module). Buy I'm facing the error: Error:cannot access Retrofit Other instances like Picasso was injected with success, I just have problems with Retrofit. My Module @Module class NetworkModule { @Provides @Singleton fun providesRetrofit(): Retrofit { return Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create()) .baseUrl(URL_BASE) .build() } @Provides @Singleton fun providesPicasso

Dagger 2 cannot access Retrofit

a 夏天 提交于 2020-04-08 09:03:56
问题 I'm trying to provide an instance of Retrofit to my Repository using Dagger 2 (with Android module). Buy I'm facing the error: Error:cannot access Retrofit Other instances like Picasso was injected with success, I just have problems with Retrofit. My Module @Module class NetworkModule { @Provides @Singleton fun providesRetrofit(): Retrofit { return Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create()) .baseUrl(URL_BASE) .build() } @Provides @Singleton fun providesPicasso

Dagger 2, Providing Application Context in Module

情到浓时终转凉″ 提交于 2020-04-06 09:05:34
问题 Im pretty new in Android development and newer in DI. I am using Kotlin on a personal project where I am experimenting with Dagger 2. I managed to set it up for a util class, but where i need to have a context to use it to inject a class that requires a context (a sharedpref manager class), I failed. Here is my code, and here is the error ( NPE ) i am getting. Thank you in advance. my module class package com.android.pine import android.content.Context import com.android.pine.utils

Dagger 2, Providing Application Context in Module

梦想与她 提交于 2020-04-06 09:04:07
问题 Im pretty new in Android development and newer in DI. I am using Kotlin on a personal project where I am experimenting with Dagger 2. I managed to set it up for a util class, but where i need to have a context to use it to inject a class that requires a context (a sharedpref manager class), I failed. Here is my code, and here is the error ( NPE ) i am getting. Thank you in advance. my module class package com.android.pine import android.content.Context import com.android.pine.utils

How to get Context in Android MVVM ViewModel

﹥>﹥吖頭↗ 提交于 2020-04-05 07:35:42
问题 I am trying to implement MVVM pattern in my android app. I have read that ViewModels should contain no android specific code (to make testing easier), however I need to use context for various things (getting resources from xml, initializing preferences, etc). What is the best way to do this? I saw that AndroidViewModel has a reference to the application context, however that contains android specific code so I'm not sure if that should be in the ViewModel. Also those tie into the Activity

error: [Dagger/MissingBinding] Map<Class<? extends ViewModel>, Provider<ViewModel>> cannot be provided without an @Provides-annotated method

时光毁灭记忆、已成空白 提交于 2020-03-25 18:52:25
问题 I have the problem with Dagger/MissingBinding. I have red all the related answers on stackoverflow, I tried to use different versins of kotlin, gradle, dagger, I tried to use different workarounds such as kapt { correctErrorTypes = true } and kapt { generateStubs = true } , but the problem still go on. Error looks like: E:\AndroidStudioPrjcts\windygo\app\src\main\java\app\windygo\dagger\AppComponent.java:12: error: [Dagger/MissingBinding] java.util.Map<java.lang.Class<? extends androidx

Dagger 2 is not generating my component class

蹲街弑〆低调 提交于 2020-03-21 12:57:58
问题 I am working with Dagger 2 to create my dependency injection. It was working a few hours ago but now the components aren't generated anymore. Here is where I am creating the components: public class App extends Application { CacheComponent mCacheComponent; ApiComponent mApiComponent; DataBaseComponent mDataBaseComponent; @Override public void onCreate() { super.onCreate(); mCacheComponent = DaggerCacheComponent.builder() .cacheModule(new CacheModule(getApplicationContext())) .build();

annotationProcessor + androidTest + dagger2

最后都变了- 提交于 2020-03-18 11:17:57
问题 For instrumented tests, I have a TestApplication that creates a TestComponent , but the file is not generated anymore ( Error:/xxx/TestApplication.java:16: The import.xxx.DaggerTestApplicationComponent cannot be resolved ). I'm not able to identify the root cause. I've tried different Android Studio (2.2, 2.1.2), different gradle plugin (2.2.0-alpha6, 5, 4) and different versions of dagger (2.2 to 2.6). Should I use androidTestAnnotationProcessor ? (that was not the case before) edit: to use

Espresso generating FileNotFoundException, when used with Dagger

杀马特。学长 韩版系。学妹 提交于 2020-03-18 10:41:54
问题 I have been wrestling with a legacy Android app, attempting to add testing and proper architecture to it. The app has a main LaunchActivity which runs a series of checks on launch. Originally, the activity was using Dagger to, rather poorly, 'inject dependencies' that the activity would use to run checks. I shifted gears to MVVM, so that I could test the view model separately, without instrumentation, and would only need to inject a mocked view model for UI tests. I followed this article to

Espresso generating FileNotFoundException, when used with Dagger

瘦欲@ 提交于 2020-03-18 10:41:15
问题 I have been wrestling with a legacy Android app, attempting to add testing and proper architecture to it. The app has a main LaunchActivity which runs a series of checks on launch. Originally, the activity was using Dagger to, rather poorly, 'inject dependencies' that the activity would use to run checks. I shifted gears to MVVM, so that I could test the view model separately, without instrumentation, and would only need to inject a mocked view model for UI tests. I followed this article to