dagger-2

Trying to get my head around dependency injection on Android with Dagger2

南楼画角 提交于 2019-12-01 10:16:31
问题 I have the following code working: SomeClass public class SomeClass { @Inject @Named("special") OkHttpClient mOkHttpClient; public SomeClass(Activity activity) { ((MyApplication) activity.getApplication()).getApplicationComponent().inject(this); } } ApplicationModule @Module public class ApplicationModule { private final Application mApplication; public ApplicationModule(Application application) { mApplication = Preconditions.checkNotNull(application); } @Provides @Singleton Application

Dagger 2.0 - AppEngine - gradle configuration

孤街醉人 提交于 2019-12-01 08:29:07
问题 I am trying to move from Dagger 1.2.2 to Dagger 2.0.1 in AppEngine project ( NOT Android one). With Dagger 1.2.2 simple: compile 'com.squareup.dagger:dagger-compiler:1.2.2' compile 'com.squareup.dagger:dagger:1.2.2' did the trick. With Dagger 2.0.1: compile 'com.google.dagger:dagger-compiler:2.0.1' compile 'com.google.dagger:dagger:2.0.1' does not work (source is generated but mixed up with *.class files in build/classes/main/..package../). 回答1: You can also do it without net.ltgt.apt plugin,

Inject ViewModelFactory.Provider in activity for espresso testing

守給你的承諾、 提交于 2019-12-01 07:39:37
Related to this question: Espresso, Dagger2 set ViemodelProvider.Factory on BaseActivity I went through hell and back to get a ViewModelFactory.Provider on an Activity during my tests, in order to get espresso tests working regarding Android Architecture Components. I expected it to be simple, but I guess it's not... The example to get it working with fragments is straightforward: https://github.com/googlesamples/android-architecture-components/blob/master/GithubBrowserSample/app/src/androidTest/java/com/android/example/github/ui/user/UserFragmentTest.java @Before public void init() {

How to create custom scoped modules in dagger 2.10

眉间皱痕 提交于 2019-12-01 06:23:47
I am trying to migrate the company app to dagger 2.10 and the AndroidInjector.inject method, but I think I found a problem. The app uses custom scopes… like the feature Login has 3 activities (each one with it`s own dagger module) and one LoginModule that is responsible for sharing singletons that only should live in this scope. So in the first Activity I used to execute something like: public class LoginActivity extends AppCompatActivity{ public void onCreate(Bundle bla){ LoginActivityComponent activityComponent = ((CustomApplication) getApplicationContext()) .plus(new LoginModule()) //

Inject ViewModelFactory.Provider in activity for espresso testing

一笑奈何 提交于 2019-12-01 05:34:20
问题 Related to this question: Espresso, Dagger2 set ViemodelProvider.Factory on BaseActivity I went through hell and back to get a ViewModelFactory.Provider on an Activity during my tests, in order to get espresso tests working regarding Android Architecture Components. I expected it to be simple, but I guess it's not... The example to get it working with fragments is straightforward: https://github.com/googlesamples/android-architecture-components/blob/master/GithubBrowserSample/app/src

error: incompatible types: NonExistentClass cannot be converted to Annotation @error.NonExistentClass()

女生的网名这么多〃 提交于 2019-12-01 04:36:20
I am trying to generate Doka docs of my project. While generating I am getting an error like above. I have searched so many but could not able to get solution to this. I have gone through this link also. Here it is saying it might be a dagger related issue. I have tried these all solution also but not worked for me. I am posting here my all Gradle files for more clarification. if any one faced this issue or know the way to solve Please do comments. Project Gradle : buildscript { ext.kotlin_version = '1.3.20' ext.dokkaVersion = '0.9.17' repositories { google() jcenter() } dependencies {

Dagger2 Qualifier not working with Kotlin?

左心房为你撑大大i 提交于 2019-12-01 04:02:30
I have a simple class as below class MainString(val msg: String) I want to inject with different argument to it, so I use the @Named Qualifier as per the guide shown in https://google.github.io/dagger/users-guide With that my AppModule has @Provides @Named("Two") fun provideTwoMainString(): MainString { return MainString("Two") } @Provides @Named("One") fun provideOneMainString(): MainString { return MainString("One") } And in my MainActivity, I just call @Inject @Named("One") lateinit var stringOne: MainString @Inject @Named("Two") lateinit var stringTwo: MainString However, when I compile,

java.lang.IllegalStateException: endPosTable already set

泪湿孤枕 提交于 2019-12-01 02:33:39
Trying to build an alexa (amazon:echo) skills set. At the same time, trying to use this experience as a learning testbed for dependency injection through dagger 2. However, building the package using maven-2 cmd: mvn assembly:assembly -DdescriptorId=jar-with-dependencies package'. to generate a zip jar with the complete dependencies produces the following exception trace: [INFO] ------------------------------------------------------------------------ [INFO] Building Echo Device Client 1.0 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven

ERROR : error.NonExistentClass Kotlin In multi module Dagger project

淺唱寂寞╮ 提交于 2019-12-01 02:12:52
I'm using Dagger 2 and Kotlin for Android development. My project is also a multi-module project. My settings.gradle file is like this: include :app include :lib I'm also maintaining the lib module. In the Dagger Files (for example in the component), I try to get the item from other module. For example: @Component interface AppComponent{ fun getPresenter() : Presenter } The Presenter object is defined in lib module. I was working in linux environment and I'm using Android Studio 3 preview canary 5. The code is working well and I am able to generate APK. But my company wanted to generate the

error: incompatible types: NonExistentClass cannot be converted to Annotation @error.NonExistentClass()

我与影子孤独终老i 提交于 2019-12-01 02:00:47
问题 I am trying to generate Doka docs of my project. While generating I am getting an error like above. I have searched so many but could not able to get solution to this. I have gone through this link also. Here it is saying it might be a dagger related issue. I have tried these all solution also but not worked for me. I am posting here my all Gradle files for more clarification. if any one faced this issue or know the way to solve Please do comments. Project Gradle : buildscript { ext.kotlin