Kotlinを使用したプロジェクトにcom.google.dagger:dagger-Android-support依存関係を追加した後、このgradleエラーが発生します。
これは私のビルドgradleの一部ですbuild.gradle
apply plugin: 'com.Android.application'
apply plugin: 'kotlin-Android'
apply plugin: 'realm-Android'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'kotlin-kapt'
Android {
...
kapt {
generateStubs = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.Android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.Android.support', module: 'support-annotations'
})
...
kapt "com.google.dagger:dagger-compiler:${daggerVersion}"
kapt "com.google.dagger:dagger-Android-processor:${daggerVersion}"
compile "com.google.dagger:dagger:${daggerVersion}"
compile "com.google.dagger:dagger-Android-support:${daggerVersion}"
...
}
そしてここでgradle error私が得る
ApplicationComponent.Java:21: error: [dagger.Android.AndroidInjector.inject(T)] Java.util.Map<Java.lang.Class<? extends Android.support.v4.app.Fragment>,javax.inject.Provider<dagger.Android.AndroidInjector.Factory<? extends Android.support.v4.app.Fragment>>> cannot be provided without an @Provides-annotated method.
e:
public interface ApplicationComponent {
e: ^
e: Java.lang.IllegalStateException: failed to analyze: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing
at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:57)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:144)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:167)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.Java:182)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.execCompiler(CompileServiceImpl.kt:397)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execCompiler(CompileServiceImpl.kt:99)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:365)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:99)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$2$$special$$inlined$withValidClientOrSessionProxy$lambda$1.invoke(CompileServiceImpl.kt:798)
at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$2$$special$$inlined$withValidClientOrSessionProxy$lambda$1.invoke(CompileServiceImpl.kt:99)
at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
ApplicationComponent
@Singleton
@Component(modules = {AndroidInjectionModule.class, ApplicationModule.class, RetrofitModule.class, ActivityBuilderModule.class})
public interface ApplicationComponent {
@Component.Builder
interface Builder {
@BindsInstance
Builder application(Application application);
ApplicationComponent build();
}
void inject(TaskApplication application);
}
誰もが同じ問題を抱えていましたか?
Android.support.v4.app.Fragmentを使用したら、AndroidSupportInjectionModuleを使用して解決します。
@Singleton
@Component(modules = {AndroidSupportInjectionModule.class, ApplicationModule.class, RetrofitModule.class, ActivityBuilderModule.class})
public interface ApplicationComponent {
@Component.Builder
interface Builder {
@BindsInstance
Builder application(Application application);
ApplicationComponent build();
}
void inject(TaskApplication application);
}
アプリレベルのgradleファイルにkaptを追加してみましたか?
kapt {
generateStubs = true
}