dagger

Android functional testing with Dagger

不羁岁月 提交于 2019-12-03 11:12:34
I’m trying to test an Activity with Mockito & Dagger . I have been able to inject dependencies to Activity in my application but when testing the Activity, I have not been able to inject mock to the Activity. Should I inject Activity to test or let getActivity() create it? public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> { @Inject Engine engineMock; private MainActivity mActivity; private Button mLogoutBtn; public MainActivityTest() { super(MainActivity.class); } @Override protected void setUp() throws Exception { super.setUp(); // Inject engineMock to test

dagger android support to androidx.fragment

老子叫甜甜 提交于 2019-12-03 10:22:38
How to inject a fragment from the package androidx.fragment.app.Fragment ? I'm using the dagger-android framework to inject my dependencies in my code. As the documentation says I do this to inject my fragment @Override public void onAttach(Activity activity) { AndroidInjection.inject(this); super.onAttach(activity); // ... } the problem is that AndroidSupportInjection class accept only fragments of the package android.support.v4.app.Fragment or if I use AndroidInjection class only accept fragments of the package android.app.Fragment and I want to use fragments of the androidx.fragment.app

Gradle dagger lint: ignore by package

不想你离开。 提交于 2019-12-03 10:12:07
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 reference in library; not included in Android: javax.annotation.processing. Referenced from dagger

Uncaught translation error: com.android.dx.cf.code.SimException: local 0007: invalid

匿名 (未验证) 提交于 2019-12-03 09:05:37
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I don't use Proguard. The project is building successfully but when I try to run on the device it shows this error. I was working in Android Studio 3.0 with a Kotlin project and it was really bad experience. I decided to switch back to 2.3 AS but the problem is still the same. The log is smaller but the exception text is the same. apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-android-extensions' tasks.withType(JavaCompile) { options.fork = true options.incremental =

AndroidInjector&lt;android.app.Activity&gt; cannot be provided without an @Provides- or @Produces-annotated method

匿名 (未验证) 提交于 2019-12-03 08:51:18
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm getting the error while trying to get the new Android dagger classes from Dagger v2.11 working in our project. I'm not exactly sure what the problem is, as I've taken into account the Android documentation over at https://google.github.io/dagger//android.html and still cannot get over this issue. Any ideas on what's wrong with this setup? MyApplication: public class MyApplication extends Application implements HasActivityInjector { @Inject AndroidInjector<Activity> androidInjector; @Override public void onCreate() { super.onCreate();

Dagger - class has no injectable members

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to integrate Dagger into my application. And I ran into a problem. I'm getting this error at runtime: java . lang . IllegalStateException : Errors creating object graph : com . app . NavigationController has no injectable members . Do you want to add an injectable constructor ? required by class com . app . fragments . LoginFragment I tried looking into other, similar answers, but nothing helped me so far... Everything related to graph construction is implemented pretty much like in Android Activity Graphs example. I

How can I build a Dagger-based Android library without forcing consuming applications to use Dagger?

天大地大妈咪最大 提交于 2019-12-03 07:14:11
问题 I'm working on an Android library that is basically a client for some REST services I've written. I have several storage classes, network queues, parsers, and so on, and like many such classes, they have dependencies on Context or on things like SharedPreferences that are constructed from Context . These objects are all hidden behind a facade class, so consumers of my library don't see them or interact with them directly. For my own sanity, I would like to use Dagger 2 for dependency

What is actual usage of “HasFragmentInjector” in Dagger 2

泄露秘密 提交于 2019-12-03 07:10:13
问题 I have implemented dagger2 v2.2 previously but as now they have added dagger.android part also. so I am creating sample project with that. I am aware about old methodology of @Provide and @Modules and @Components etc annotations but from Dagger 2.8+ they have added this android-support library also which have some new Injections like @ActivityKey , @ContributesAndroidInjector , @Subcomponent.Builder etc. So my question is what benefits it brings to the table. Does it resolve problems like

Use Dagger modules without the “injects” directive

[亡魂溺海] 提交于 2019-12-03 06:42:45
问题 I am trying to make Dagger work without the "injects" directive inside the @Module annotation. I am basing my test project on the Android Simple Dagger example This is the part that is giving me problems: @Module( injects = HomeActivity.class, complete = false ) public class DemoModule { // TODO put your application-specific providers here! } (Edit): Which in my code is CTXModules.java The part that I'd like to remove is the "injects = HomeActivity.class". I know I can mark my own modules

flink - using dagger injections - not serializable?

情到浓时终转凉″ 提交于 2019-12-03 06:21:34
Im using Flink (latest via git) to stream from kafka to cassandra. To ease unit testing Im adding dependency injection via Dagger. The ObjectGraph seems to be setting itself up properly but the 'inner objects' are being flagged as 'not serializable' by Flink. If I include these objects directly they work - so what's the difference? Class in question implements MapFunction and @Inject a module for cassandra and one for reading config files. Is there a way to build this so I can use late binding or does Flink make this impossible? Edit: fwiw - Dependency injection (via dagger) and