Tag: dagger 2

android gradle build:生成的类列表不存在

当我尝试在android studio 2.3.2中构建我的android应用程序时,出现以下单个错误: Error:Execution failed for task ':viewmodel:transformClassesAndResourcesWithSyncLibJarsForRelease'. > failure, see logs for details. Generated class list does not exist MyPath\viewmodel\build\intermediates\data-binding-info\release\_generated.txt 该文件夹确实是空的,我在调试,而不是释放(但也调试是空的)构建这整个事情。 我使用匕首(2.10)进行依赖注入,这可能是这个问题的根源,但是我无法真正在网络上找到这个错误的帮助。 这个模块的gradle.build文件: apply plugin: 'com.android.library' apply plugin: 'com.neenbedankt.android-apt' android { def rootConfig = rootProject.ext compileSdkVersion rootConfig.androidCompileSdkVersion buildToolsVersion rootConfig.androidBuildToolsVersion dataBinding { enabled = true } defaultConfig { minSdkVersion rootConfig.androidMinSdkVersion targetSdkVersion rootConfig.androidTargetSdkVersion versionCode rootConfig.applicationVersionCode versionName […]

Dagger2注射咖啡测试

我想在我的Espresso测试中注入由匕首创建的组件。 组件应该是一样的,所以,没有必要用匕首来压倒任何东西。 我有以下班级: @RunWith(AndroidJUnit4.class) public class AccountRepositoryTest { @Inject AccountRepository repository; @Before public void setUp() throws Exception { new DaggerTestComponent().builder().build().inject(this); } } 由于我不能将AccountRepositoryTest添加到我的主要DaggerComponent类,所以我在我的androidTests文件夹中创建了另一个组件类: @Singleton @Component(modules = arrayOf(AppModule::class, DatabaseModule::class, RepositoryModule::class)) interface TestComponent: AppComponent { fun inject(accountRepositoryTest: AccountRepositoryTest) } 但是匕首永远不会从TestComponent接口生成ComponentClass,当我编译代码时,我总是收到这个错误: Error:(26, 7) error: cannot find symbol class DaggerTestComponent 如果我评论这行,我的代码会被编译,所以我确信这只是防止匕首生成类。 所以我的问题是:如何使匕首从androidTests文件夹中定义的接口生成组件类?

不要在即时应用程序功能模块中生成类

我在我的android应用程序中使用dagger2。 即使没有错误,它也不会生成匕首组件类。 我已经在设置中启用了注释处理器,并重新启动了我的android工作室,但是这对我不起作用。 我也读这个线程Dagger2不生成Daggercomponent类,并阅读一个线程, apt被弃用,所以我使用annotationProcessor 基本模块build.gradle apply plugin: 'com.android.feature' apply plugin: 'kotlin-android' apply plugin: 'kotlin-kapt' android { compileSdkVersion 26 buildToolsVersion "26.0.1" baseFeature true defaultConfig { minSdkVersion 23 targetSdkVersion 26 versionCode 1 versionName "0.0.1" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { application project(':app') feature project(":main") feature project(":tv") api […]

删除ButterKnife后匕首崩溃

我一起使用匕首和刀。 现在我正在删除butterknife,因为我现在使用kotlin合成属性。 但是当从项目中删除黄油刀时,我正在建造这个匕首时崩溃: :android:compileWithMapsWithAnalyticsForPlayDebugKotline: java.lang.NullPointerException at dagger.shaded.auto.common.MoreElements.asType(MoreElements.java:126) at dagger.shaded.auto.common.MoreElements.getAnnotationMirror(MoreElements.java:212) at dagger.shaded.auto.common.MoreElements.isAnnotationPresent(MoreElements.java:199) at dagger.internal.codegen.InjectValidator.validateMembersInjectionType(InjectValidator.java:263) at dagger.internal.codegen.InjectBindingRegistry.tryRegisterMembersInjectedType(InjectBindingRegistry.java:264) at dagger.internal.codegen.InjectBindingRegistry.tryRegisterMembersInjectedType(InjectBindingRegistry.java:248) at dagger.internal.codegen.InjectProcessingStep$1.visitVariableAsField(InjectProcessingStep.java:69) at dagger.internal.codegen.InjectProcessingStep$1.visitVariableAsField(InjectProcessingStep.java:59) at javax.lang.model.util.ElementKindVisitor6.visitVariable(ElementKindVisitor6.java:229) at org.jetbrains.kotlin.java.model.elements.JeVariableElement.accept(JeVariableElement.kt:51) at dagger.internal.codegen.InjectProcessingStep.process(InjectProcessingStep.java:58) at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:329) at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:182) at org.jetbrains.kotlin.annotation.AbstractAnnotationProcessingExtension.doRound(AnnotationProcessingExtension.kt:312) at org.jetbrains.kotlin.annotation.AbstractAnnotationProcessingExtension.process(AnnotationProcessingExtension.kt:252) at org.jetbrains.kotlin.annotation.AbstractAnnotationProcessingExtension.doAnnotationProcessing(AnnotationProcessingExtension.kt:239) at org.jetbrains.kotlin.annotation.AbstractAnnotationProcessingExtension.analysisCompleted(AnnotationProcessingExtension.kt:131) at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.java:160) at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(TopDownAnalyzerFacadeForJVM.java:79) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.analyze(KotlinToJVMBytecodeCompiler.kt:362) at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:126) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:355) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:130) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:183) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52) […]

注入不能与第二个构造函数一起使用

对于我当前的项目,我正在使用Kotlin和Dagger 2.我想在二级构造函数中注入依赖项,但构造函数从未初始化。 class SelectionFragmentModel ():ViewModel(){ lateinit var channelInfosRepository: ChannelInfosRepository @Inject constructor(channelInfosRepository: ChannelInfosRepository) : this(){ this.channelInfosRepository = channelInfosRepository } … } 作为一种解决方法,我目前正在注入主构造函数,但这不是最佳的。 class SelectionFragmentModel @Inject constructor(private val channelInfosRepository: ChannelInfosRepository):ViewModel(){ constructor() : this(ChannelInfosRepository()) … } 我错过了什么吗?

匕首不生成/测试类的组件

我在这里遵循指南: https : //github.com/ecgreb/dagger-2-testing-demo 我有我的应用程序/ src / main(注入和@Provides代码省略)下面的设置: public class FlingyApplication extends Application { @Singleton @Component(modules = { FlingyModule.class }) public interface FlingyComponent } @Module public class FlingyModule 在app / src / test中: public class TestFlingyApplication extends Application { @Singleton @Component(modules = { TestFlingyModule.class }) public interface TestFlingyComponent extends FlingyComponent } @Module public class TestFlingyModule […]

Dagger2 – FragmentSubcomponentBuilder没有实现AndroidInjector.Factory

我正在使用匕首2并试图将我的Android项目从Java转换为Kotlin。 成功构建后,我得到运行时错误: MyFragmentSubcomponentBuilder没有实现AndroidInjector.Factory 用Java这个错误没有出现。 我还注意到,在我的ActivityBuilder模块中,所有方法在构建之后都是未使用的(它们必须在生成的子组件类中使用)。 @Module abstract class ActivityBuilder { // … @ContributesAndroidInjector(modules = arrayOf(MainActivityModule::class,MyFragmentProvider::class)) internal abstract fun bindMainActivity(): MainActivity // this method highlighted with gray color in AndroidStudio as unused } 我如何设置我的项目正确使用匕首2和kotlin? 我的顶级gradle.build: buildscript { ext.kotlin_version = '1.1.51' repositories { jcenter() maven { url 'https://maven.google.com' } mavenCentral() google() maven { url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo' } maven […]

Kotlin匕首2 Android ViewModel注入错误

我试图在我的Android应用程序上使用匕首2从arch android库注入新的ViewModel。 从我看到的这个示例https://github.com/googlesamples/android-architecture-components/tree/e33782ba54ebe87f7e21e03542230695bc893818/GithubBrowserSample我需要使用这个: @MustBeDocumented @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) @Retention(AnnotationRetention.RUNTIME) @MapKey internal annotation class ViewModelKey(val value: KClass<out ViewModel>) @Module abstract class ViewModelModule { @Binds @IntoMap @ViewModelKey(LoginViewModel::class) internal abstract fun bindLoginViewModel(viewModel: LoginViewModel): LoginViewModel @Binds @IntoMap @ViewModelKey(MainMenuViewModel::class) internal abstract fun bindSearchViewModel(viewModel: MainMenuViewModel): MainMenuViewModel @Binds internal abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory } @ApplicationScope @Component(modules = arrayOf(ApplicationModule::class, NetworkModule::class, ViewModelModule::class)) interface […]

匕首2生成的测试组件不被识别

我希望这只是我在这里做错了。 我试图使用Dagger 2.0为我的JUnit测试注入依赖( 不是Espresso测试 ,只是纯JUnit)。 所以,我有一个“主”的Java模块和一个“测试”的Java模块。 在主模块中,我有一个Dagger模块和一个组件: @Module public class MainModule { @Provides public Widget provideWidget() { return new ConcreteWidget(); } } … @Component (modules = MainModule.class) public interface MainComponent { void inject(WidgetConsumer consumer); } 在我的测试模块中,我有以下几点: @Module public class TestModule { @Provides public Widget provideWidget() { return new Widget() { @Override public void doThing() { […]

从1.0.2 – 1.0.3升级Kotlin:java.lang.NoSuchMethodError:没有虚方法provideInjectedData $ app_compileDebugKotlin()

我有一个Kotlin咖啡Dagger2小项目。 当我使用Kotlin 1.0.2时效果很好。 迁移到Kotlin 1.0.3后,运行Espresso Instrumental测试(在MainActivityTest上)时,出现上述错误。 我的Dagger2 TestModule如下 @Module open class ApplicationTestModule(protected val mApplication: Application) { @Provides internal fun provideApplication(): Application { return mApplication } @Provides @Singleton internal fun provideInjectedData(): InjectedData { return mock(InjectedData::class.java) } } 为InjectedData生成的ApplicationTestModule的dagger2如下 package com.elyeproj.kotlinespressomock; import dagger.internal.Factory; import dagger.internal.Preconditions; import javax.annotation.Generated; @Generated( value = "dagger.internal.codegen.ComponentProcessor", comments = "https://google.github.io/dagger" ) public final […]