dagger

AndroidAnnotations and Dagger

别来无恙 提交于 2019-12-05 02:44:34
I'm trying to use Dagger to inject into an android Annotated Activity. java.lang.IllegalArgumentException: No inject registered for members/com.app.server.AddServerActivity_. You must explicitly add it to the 'injects' option in one of your modules. If I try and Add the com.app.server.AddServerActivity_ to the module I get a diffrent error Error: java.lang.ClassCastException: com.sun.tools.javac.code.Attribute$Error cannot be cast to com.sun.tools.javac.code.Attribute$Class java.lang.RuntimeException: java.lang.ClassCastException: com.sun.tools.javac.code.Attribute$Error cannot be cast to com

How to inject into static classes using Dagger?

假如想象 提交于 2019-12-05 01:47:24
I want to introduce dependency injection through Dagger to a project. The following code acts as an example to describe the problem of injection into static classes . The static method setupTextView() is called from multiple classes: public abstract class TextViewHelper { public static void setupTextView(TextView textView, Spanned text, TrackingPoint trackingPoint) { textView.setText(text, TextView.BufferType.SPANNABLE); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { MyApp.getTracker

Android Dagger Dependency Injection fails on private Fields

纵饮孤独 提交于 2019-12-04 22:53:16
I'm new to dagger (though I have experience with DI from working on Java EE WebApps using Weld). What I'm trying to do is to inject a dependency into a class. The field is private. Dagger then throws an exception stating it can't inject into a private field. What's the reason for that? After all it is possible to write to private fields using reflections, even on android.. If I set the visibility of the field to something other than private the injection seems to work. Making a private field 'package visible' may not always be what you want. The Dagger documentation suggests the following:

Android Dagger 2: Inject versus Provides

末鹿安然 提交于 2019-12-04 16:50:17
问题 I have a question regarding Android Dagger 2 und the usage of @Inject and @Provide annotations. Given are the following two simplified examples: public class A { String msg; public A(String msg){ this.msg = msg; } } public class B { public A a; public B(A a){ this.a = a; } } @Module public class AModule { @Provides A providesA(){ return new A("blah"); } @Provides B ProvidesB(A a) { return new B(a); } } The example is pretty straight forward, I have two methods in my AModule with @Provides

Gradle dagger lint: ignore by package

跟風遠走 提交于 2019-12-04 16:04:51
问题 I've created an Android project using Gradle. I've added a Dagger library: dependencies { compile 'com.squareup.dagger:dagger-compiler:1.2.1' compile 'com.squareup.dagger:dagger:1.2.1' } After trying to compile the project I get a build failure due to lint exceptions: InvalidPackage: Package not included in Android ../../../../../../.gradle/caches/modules-2/files-2.1/com.squareup.dagger/dagger-compiler/1.2.1/c8bf6c2fda9b27f4d44a2aa4280df525a1408771/dagger-compiler-1.2.1.jar: Invalid package

How can I replace Activity scoped dependencies with mocks using Dagger2

↘锁芯ラ 提交于 2019-12-04 12:40:51
I have a scoped dependency in my Activity and I want to test that activity with some mocks. I have read about different approach that suggest to replace Application component with a test component during the test, but what I want is to replace the Activity component. For example, I want to test the Activity against mock presenter in my MVP setup. I believe that replacing component by calling setComponent() on Activity will not work, because Activity dependencies already injected via field injection, so during the test, real object will be used. How can I resolve this issue? What about Dagger1?

Dagger - nested injections, is it necessary to call inject()?

蹲街弑〆低调 提交于 2019-12-04 11:59:05
I'm new to Dagger and at the begininig I face some issues. I have simple structure so far in my project. My injection module: @Module( injects = {GameBoardFragment.class, GameManager.class}, complete = false, library = true ) public class GameObjectsProviderModule { private final Application mApplication; public GameObjectsProviderModule(Application application){ this.mApplication = application; } @Provides @Singleton public GameManager provideGameManager(){ return new GameManager(); } @Provides public Board getBoard(){ return new Board(); } @Provides @Singleton @ForApplication Context

Google Auto Factory: not annotated with @Provided?

隐身守侯 提交于 2019-12-04 11:17:30
So I'm trying out google auto factory but I get a strange error. Factory class: @AutoFactory( className = "MembersAdapterFactoryImpl" ) public class MembersAdapter extends ArrayAdapter<Member> { /** * Get an instance of the helper */ private MembersAdapterHelper mMembersAdapterHelper; public MembersAdapter(@Provided MembersAdapterHelper membersAdapterHelper, Context context, int resource, List<Member> members){ super(context, resource, members); mMembersAdapterHelper = membersAdapterHelper; } } Generated class: package me.magneto.groups.adapters; import javax.annotation.Generated; import javax

Dagger 2.10/2.11 injecting Activity failing

爱⌒轻易说出口 提交于 2019-12-04 09:46:54
问题 I have been trying to, unsuccessfully, inject the Activity in a class ViewUtils. I have followed a couple of different posts but I can't seem to understand what am I missing in my implementation. I know this is probably a repetition of the posts below and I really apologize for that but I honestly cannot see what am I missing. These are the posts I've found: Dagger 2.10 Android subcomponents and builders How to create custom scoped modules in dagger 2.10 https://google.github.io/dagger

CustomView dependency injection with dagger 2 (within activity scope)

二次信任 提交于 2019-12-04 08:23:51
问题 My question is similar to this. So for instance, I have a LiveData implementation: public class CustomLiveData extends LiveData<SomeEvent> { @Inject public CustomLiveData(@ActivityContext Context context) { //.... } } that I want to inject into a custom view: public class CustomView extends View { @Inject SomeApplicationProvider anyProvider; @Inject CustomLiveData dataProvider; // Getting @com.di.qualifiers.ActivityContext android.content.Context cannot be provided without an @Provides