dagger

ClassCastException: Application object is not my custom application object

二次信任 提交于 2019-12-11 18:36:41
问题 Often in Android code we use this pattern of storing data in the Application object and then accessing it via casting as such: ((MyApplicationObject)getApplication()).getDaggerComponent() getApplication() should always be MyApplicationObject because I have specified it in the AndroidManifest.xml . However, when you deploy this code, sometimes it causes a ClassCastException and we get a different object instead. How can this be? What is the correct workaround for this issue? 回答1: Resolved in

Android error: cannot find symbol class DaggerAppComponent

蓝咒 提交于 2019-12-11 17:56:11
问题 My colleague developed an Application according to this repository and I should make some changes In my case After some changes and remove Google Room Library I faced this problem: error: cannot find symbol class DaggerApplicationComponent After several rebuilds still cannot generate Project dagger2Version = '2.20' implementation "com.google.dagger:dagger:$rootProject.dagger2Version" annotationProcessor "com.google.dagger:dagger-compiler:$rootProject.dagger2Version" implementation "com.google

How to dynamically pass different urls in retrofit2 android using Dagger

守給你的承諾、 提交于 2019-12-11 17:53:36
问题 In the ApplicationClass I'm passing one url and i use it in ActLogin.java Now I want to pass ActUpcomingEvents another url different than ActLogin.java How to achieve this NetModule.java @Module public class NetModule { String mBaseUrl; Application mApplication; // Constructor needs one parameter to instantiate. public NetModule(String baseUrl, Application application) { this.mBaseUrl = baseUrl; this.mApplication = application; } // Dagger will only look for methods annotated with @Provides

Dagger - Setting a Dynamic Value to SubComponent Builder [duplicate]

帅比萌擦擦* 提交于 2019-12-11 17:38:10
问题 This question already has answers here : Dagger 2.10 Android subcomponents and builders (2 answers) Closed last year . I want to set a value to my sub-component builder at the time of building it. If simple Dagger 2 is concerned, we can achieve like following: @UserScope @Subcomponent(modules = {UserModule.class, ActivityBuilder.class, NewEditQuotationModule.class}) public interface UserComponent { NewEditQuotationComponent.Builder getNewEditQuotationComponent(); void inject(UserManager

Dagger Scope conflict

折月煮酒 提交于 2019-12-11 17:01:47
问题 Reprository : https://github.com/googlesamples/android-architecture Branch - todo-mvp-dagger It is found that TaskFragment is injected using contructorinjection For instance : In the TasksModule, I want to add another module for task fragment like below for field Injection in the TaskFragment @Module class TasksModule{ @Fragmentscoped @contributesandroidinjector(modules = AnotherModule.class) abstract TasksFragment tasksFragment(); } @Module public class AnotherModule { @Provides

How to pass a String to a ViewModel/Repository class using Dagger2 in Android?

拜拜、爱过 提交于 2019-12-11 15:59:40
问题 This is my fragment class: public class MyFragment extends DaggerFragment { @Inject MyViewModelFactory factory; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { String uid = "123"; //How to pass this String?? MyViewModel viewModel = ViewModelProviders.of(this, factory).get(MyViewModel.class); LiveData<User> liveData = viewModel.getUserLiveData(); } } Now this is MyViewModel class: public class MyViewModel extends ViewModel { private

Dagger 2: injecting singleton with lots of access points

大憨熊 提交于 2019-12-11 14:29:43
问题 I just started with DI / Dagger 2. I have a huge project. To try dagger 2, I started with injecting my singleton class 'MyPreferences'. This class handles all app actions from and to the SharedPreferences. Auto-injecting the SharedPreferences in the MyPreferences went perfectly. However, I am using this singleton in about 50 classes, I used to do this: MyPreferences.getInstance(context).getXXXSetting(); I have changed this to dagger2 injection in a few classes, and it works fine, but I find

Dagger throw a NoSuchMethodException when creating the graph

冷暖自知 提交于 2019-12-11 12:56:26
问题 I am using Dagger as dependency injection framwork. It's working well so far but I am having an issue while using Dagger for Android unit testing and can't figure out why (Probably because of an incorrect use of Dagger). I am having the following exception java.lang.IllegalArgumentException: Failed to construct com.couchsurfing.mobile.android.CSApplication$ProdModule at dagger.internal.plugins.reflect.ReflectiveModuleAdapter.newModule(ReflectiveModuleAdapter.java:94) at dagger.internal

Android Customize Workflow for Product Flavors

房东的猫 提交于 2019-12-11 12:38:34
问题 I have an app with a bunch of product flavors which are basically white labels of a single app. However, once in a while, there is some divergence from the main flow in some flavor because the client wants something slightly different. So far, we have been editing the code for those cases and using spaghetti code (lots of ifs and elses) to make sure the other apps don't break. Needless to say this isn't a very scalable (or even sane) way to do this. One option would be to write the activity

Dagger field injection not working with simple java classes

送分小仙女□ 提交于 2019-12-11 10:39:00
问题 I am trying field injection with dagger although constructor injection is working absolutely fine but i don't know what is wrong with field injection. May be I am doing wrong. I am adding the code snippets. I am getting null pointer exception on engine.start() because the engine dependency is not fed. It is similar to A->B->C dependencies where A->B is fed but B->C is not. Its been long I am unable to resolve. package com.raghav.java.car; import javax.inject.Inject; public class App { @Inject