dagger-2

How to use Dagger in Java library module in Android Studio?

ぐ巨炮叔叔 提交于 2021-02-17 01:58:23
问题 I'm using Dagger in a Java library module in an Android Studio project and here's what my build.gradle for the module looks like: apply plugin: 'java-library' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.google.dagger:dagger:2.24' annotationProcessor 'com.google.dagger:dagger-compiler:2.24' } sourceCompatibility = "7" targetCompatibility = "7" I can see that the Dagger is properly generating implementations and they are present in build/generated

Dagger2: Using CompositeDisposable with Android Paging Library

。_饼干妹妹 提交于 2021-02-11 14:18:04
问题 I'm using Dagger2. I will be injecting CompositeDisposable in ViewModel through @Inject constructor(private val compositeDisposable: CompositeDisposable) And my screen would also be using Android Pagination library and inside PageKeyedDataSource class I would be adding every network call into compositeDisposable using it's .add(diposable) . I also would be adding CompositeDisposable in PageKeyedDataSource constructor through Dagger graph. Is there any way that CompositeDisposable in ViewModel

Using dagger-injected objects in attachBaseContext

巧了我就是萌 提交于 2021-02-08 13:11:20
问题 I need to access my SharedPreferences instance in the attachBaseContext of my activity (so I can set the locale there), but the injected SharedPreferences instance is not available there as the injection is happening in the onCreate method, which is running after the attachBaseContext call. I am using dagger2 for dependency injection. Any idea how I can avoid creating a new SharedPreferences instance? EDIT: Ok, so I think the problem is that I am trying to use dagger too much, I think in this

Using dagger-injected objects in attachBaseContext

自古美人都是妖i 提交于 2021-02-08 13:10:30
问题 I need to access my SharedPreferences instance in the attachBaseContext of my activity (so I can set the locale there), but the injected SharedPreferences instance is not available there as the injection is happening in the onCreate method, which is running after the attachBaseContext call. I am using dagger2 for dependency injection. Any idea how I can avoid creating a new SharedPreferences instance? EDIT: Ok, so I think the problem is that I am trying to use dagger too much, I think in this

Failed resolution of: Ldagger/internal/Preconditions

人走茶凉 提交于 2021-02-07 19:09:38
问题 My app worked well but due to some problem with my operating system Debian I decided to reinstall it and I choose to install Ubuntu-16.04 instead of the last Debian. Now everything is OK. The problem is my android application. After reinstalling android-studio the stable version, I can not test my application anymore. Why? Because every time I launch the application, I got this error. I don't know what it means, and after some searching on the internet, I didn't get anywhere. Here is the

Dagger 1 and Dagger 2 package names conflict

只愿长相守 提交于 2021-01-28 22:23:09
问题 I have an Android project in which one 3rd party library depends on Dagger 1 and my project on Dagger 2 . Dagger 1 and 2 have the same package names so my app is working fine, but 3rd party library is not working because of overriding dagger 1 package by dagger 2. Changing the package name of Dagger 2 to dagger2 instead of dagger is not an option because annotation compiler is generating classes with static package name dagger . Is there a way of resolving this conflict? 回答1: Use jarjar on

Why are Dagger subcomponents declared in a module and not in the parent component directly?

◇◆丶佛笑我妖孽 提交于 2021-01-28 12:26:27
问题 Why is the subcomponents = attribute set on a module of a component and not on the component directly? This doesn't seem very intuitive to me so I guess there must be a reason. @Component(modules = ExampleModule.class) public interface AppComponent @Module(subcomponents = ActivityComponent.class) public abstract class ExampleModule 回答1: In a sense, it makes more sense for subcomponents to be on modules: They're private implementation details that are not necessarily exposed publicly, and ones

Enable Annotation processing for existing projects Android studio 3.3

China☆狼群 提交于 2021-01-28 12:05:28
问题 I am using Android studio 3.3 and trying to use Dagger2 in my project. However, the annotation processing does not work in it and the annotation classes are not generated. I am add the library as follows to my gradle file. implementation 'com.google.dagger:dagger:2.21' annotationProcessor 'com.google.dagger:dagger-compiler:2.21' I have also specified the annotationProcessorOptions javaCompileOptions { annotationProcessorOptions { includeCompileClasspath true } } What have I tried: Closing the

Dagger 2.15: Appcomponent - was unable to process this interface

喜夏-厌秋 提交于 2021-01-28 06:19:06
问题 I cannot build my app with the following error: Task :app:kaptDebugKotlin debug/AppComponent.java:7: error: [ComponentProcessor:MiscError] dagger.internal.codegen.ComponentProcessor was unable to process this interface because not all of its dependencies could be resolved. Check for compilation errors or a circular dependency with generated code. public abstract interface AppComponent { ^ I'm using dagger 2.15 and got all of it's dependencies included: implementation deps.dagger.runtime

How to share view models between fragments using Google's GithubBrowserSample approach?

a 夏天 提交于 2021-01-27 12:08:01
问题 I am very new using Android architecture components, so I decided to base my application using GithubBrowserSample to achieve many of my use cases. But i have the problem that i don´t know what is the correct way to share viewmodels between fragments with this approach. I want to share the view model because i have a fragment with a viewpager with 2 fragments that need to observe data of the parent fragment view model I used this before to achieve it, based on google's documentation override