dagger

Dagger 2 component not generated

梦想的初衷 提交于 2019-12-03 04:45:51
问题 In my module, in my base Application class component = DaggerCompClassComponent.builder() .classModule(new ModuleClass()).build(); it can not find DaggerCompClassComponent. I have on module build.gradle apply plugin: 'com.neenbedankt.android-apt' ......................... apt 'com.google.dagger:dagger-compiler:2.8' compile 'com.google.dagger:dagger:2.8' provided 'javax.annotation:jsr250-api:1.0' and in Project build.gradle, classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' I have

Robolectric not using test application

旧时模样 提交于 2019-12-03 03:51:31
According to this link I can create a test application which Robolectric will automatically start using in tests. I cannot get this to work. I am using Dagger for dependency injection and have created injection wrapper classes for Activity and Application . Then each of my activities extends the wrapper activity class instead of plain old Activity . The problem I am having is that, in tests, the dependencies provided by the Application modules can't be resolved and so the tests fail. This is because most of our tests are just building an activity (using Robolectric.buildActivity() ) and aren't

Dagger and Butter Knife vs. Android Annotations

♀尐吖头ヾ 提交于 2019-12-03 02:01:58
问题 I am evaluating Dependency Injection (DI) frameworks for an Android app. The top contenders are: Dagger (with Butter Knife) and Android Annotations. I understand that Dagger and ButterKnife are from the same source- square and they complement each other. Here're are the key matrices that I am looking for: Ease of use (our build is based on Gradle and we use Android Studio IDE) Testing support (we use Robotium for functional testing and RoboLectric for unit testing) Performance (DI frameworks

Why can't dagger process these kotlin generics?

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having some weird kotlin generic issues with Dagger that I kinda fixed but the solution isn't sound. Here's the dagger classes: @Module class P5Module { @Provides fun pool(): RecyclerView.RecycledViewPool = RecyclerView.RecycledViewPool() @Provides fun adapters(fusion: P5FusionAdapter, personas: P5ListAdapter, skills: P5SkillsAdapter, info: InfoAdapter) : List = listOf(fusion, personas, skills, info) } @ActivityScope @Subcomponent(modules = arrayOf(P5Module::class)) interface P5Component { fun adapter(): PageableAdapter } interface

Dagger 2.2 component builder module method deprecated

匿名 (未验证) 提交于 2019-12-03 01:25:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I started using dagger 2.2 and the module methods in the Component builder are deprecated. This is my Application component : @Component(modules = ApplicationModule.class) public interface ApplicationComponent { void inject(Application application); } And the Application module: @Module public class ApplicationModule { Application application; public ApplicationModule(Application application) { this.application = application; } @Provides @Singleton Application providesApplication() { return application; } } Here is the generated class:

Android Studio: Unexpected top level exception (finished with non-zero exit value 2..)

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: When i'm trying to debug my android app i'm getting the following error message: Error:Execution failed for task ':app:transformClassesWithDexForDebug'. com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2 The error first appeared on adding a new dependency. This is my gradle file compile 'com.android.support

Generic @Inject'd fields in an abstract superclass

冷暖自知 提交于 2019-12-03 01:22:32
Consider a MVP-ish set of types. An abstract Presenter exists, with a View interface: public interface View { //... } public abstract class AbstractPresenter<V extends View> { @Inject V view; //... } Then, lets have a specific concrete presenter subclass, with its view interface and implementation: public interface LoginView extends View { //... } public LoginPresenter extends AbstractPresenter<LoginView> { //... } public class LoginViewImpl implements LoginView { //... } In a Dagger module, of course we would define a @Provides method: @Provides LoginView provideLoginView() { return new

Dagger: IllegalArgumentException: No injector factory bound for Class

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am new to Dagger 2. I have 2 Activities, I want to use injected ViewModel for both. Here is my ViewModuleFactory : @Singleton public class ProductViewModelFactory implements ViewModelProvider.Factory { private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators; @Inject public ProductViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) { this.creators = creators; } @SuppressWarnings("unchecked") @Override public <T extends ViewModel> T create(Class<T> modelClass) { Provider<? extends ViewModel>

Error : Program type already present: android.support.design.widget.CoordinatorLayout$Behavior

匿名 (未验证) 提交于 2019-12-03 01:10:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am getting the following error while building the project. haven't used CoordinatorLayout in this project. just added as a dependency in build.gradle : I am using Android Studio 3.2 Canary 4. LogCat AGPBI: {"kind":"error","text":"Program type already present: android.support.design.widget.CoordinatorLayout$Behavior","sources":[{}],"tool":"D8"} :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app

Dagger 2 - what is the purpose of a @Singleton annotation class

橙三吉。 提交于 2019-12-03 00:55:59
From the dagger 2 Documentation I noticed that you can have a @Singleton annotated class. What is the purpose of marking a class as @Singleton as I have tried to do this in my code but a singleton object is NOT produced. I'm not clear on what use marking my class with this annotation serves. From the documentation please focus on the following statement: The @Singleton annotation on an injectable class also serves as documentation. It reminds potential maintainers that this class may be shared by multiple threads.* @Singleton class CoffeeMaker { ... } UPDATE: After reviewing froger_mcs answer