简体   繁体   English

构建项目时崩溃匕首

[英]Crash dagger when build project

When i try to build a project for generating Dagger's files build fails with an exception. 当我尝试构建用于生成Dagger文件的项目时,构建失败,但有一个例外。 Could you please tell me how to fix it or at least in what direction look. 您能告诉我如何修复它,或者至少朝哪个方向看。

e: /home/hodzi/Projects/StudioProjects/StackViewer/app/build/tmp/kapt3/stubs/debug/com/hodzi/stackviewer/di/AppComponent.java:6: error: [com.hodzi.stackviewer.questions.di.QuestionsComponent] com.hodzi.stackviewer.questions.di.QuestionsComponent has conflicting scopes: e: e:/home/hodzi/Projects/StudioProjects/StackViewer/app/build/tmp/kapt3/stubs/debug/com/hodzi/stackviewer/di/AppComponent.java:6:错误:[com.hodzi.stackviewer.questions。 di.QuestionsComponent] com.hodzi.stackviewer.questions.di.QuestionsComponent的范围有冲突:e:

e: public abstract interface AppComponent { e: ^ e: e:公共抽象接口AppComponent {e:^ e:
com.hodzi.stackviewer.di.AppComponent also has @Singleton 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:138) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:154) at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:58) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:103) at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51) at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92) at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:386) at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:96) at org.jetbrains.kotlin.daemon.Compil com.hodzi.stackviewer.di.AppComponent也具有@Singleton e:java.lang.IllegalStateException:无法分析:org.jetbrains.kotlin.kapt3.diagnostic.KaptError:在org.jetbrains.kotlin.analyzer进行注释处理时出错。 org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(AnalogResult.throwIfError(AnalysisResult.kt:57)位于org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:138) kt:154)在org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:58)在org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:103)在org.jetbrains .kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)在org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)在org.jetbrains.kotlin.daemon.CompileServiceImpl $ compile org.jetbrains.kotlin.daemon。$ 1 $ 2.invoke(CompileServiceImpl.kt:386).org.jetbrains.kotlin.daemon.Compil $ 1 $ 2.invoke(CompileServiceImpl.kt:96)在org.jetbrains.kotlin.daemon.Compil eServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:889) at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96) at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137) at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:916) at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:888) at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:385) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:324) at sun.rmi.transport.Transport$1.run(Transport.java:200) at sun.rmi.transport.Transport$1.run(Tr 位于org.jetbrains.kotlin.daemon.CompileServiceImpl $ doCompile $$的eServiceImpl $ doCompile $$ inlined $ ifAlive $ lambda $ 2.invoke(CompileServiceImpl.kt:889)位于org.jetbrains.kotlin.daemon.CompileServiceImpl $ doCompile $$ inlined $ ifAlive $ lambda $ 2.invoke(CompileServiceImpl.kt:96)at org.jetbrains.kotlin.daemon.CompileServiceImpl上的org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)在org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:916) org.jetbrains.kotlin.daemon上的doCompile(CompileServiceImpl.kt:888).sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)处的compileServiceImpl.compile(CompileServiceImpl.kt:385)at sun.reflect.NativeMethodAccessorImpl.invoke(Native Method) java:62)位于sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)位于java.lang.reflect.Method.invoke(Method.java:498)在sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java :324)在sun.rmi.transport.Transport $ 1.run(Transport.java:200)在sun.rmi.transport.Transport $ 1.run(Tr ansport.java:197) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing at org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:90) at org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.do ansport.java:197),位于java.security.AccessController.doPrivileged(本机方法),位于sun.rmi.transport.Transport.serviceCall(Transport.java:196),位于sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport。 java.568)位于sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.run0(TCPTransport.java:826)位于sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.lambda $ run $ 0(TCPTransport.java:683)位于sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.run(TCPTransport.java:682)上的java.security.AccessController.doPrivileged(本机方法),java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) java.lang.Thread.run(Thread.java:745)上的java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)原因:org.jetbrains.kotlin.kapt3.diagnostic.KaptError:发生错误在org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.do的org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:90)处进行注释处理 AnnotationProcessing$default(annotationProcessing.kt:42) at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:205) at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:166) at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:82) at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:96) at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:106) at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:83) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:377) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytec 位于org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.run的AnnotationProcessing $ default(annotationProcessing.kt:42),位于org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:166)的AnnotationProcessing(Kapt3Extension.kt:205) .jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:82)at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM $ analyzeFilesWithJavaIntegration $ 2.invoke(TopDownAnalyzerFacade。 cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:106)位于org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegratcade $ default(TopDownAnalyzer) jvm.compiler.KotlinToJVMBytecodeCompiler $ analyze $ 1.invoke(KotlinToJVMBytecodeCompiler.kt:377)在org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler $ analyze $ 1.invoke(KotlinToJVMBytecodeCompiler $ analyze $ 1。 odeCompiler.kt:68) at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:96) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:368) at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:133) ... 30 more org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:96)处的odeCompiler.kt:68)(org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.Tok。 368)at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:133)...另外30个

Components: 组件:

1) AppComponent 1)AppComponent

@Singleton
@Component(modules = arrayOf(AppModule::class, NetModule::class))
interface AppComponent {

    fun inject(app: App)

    fun plus(questionsModule: QuestionsModule): QuestionsComponent
}

2) QuestionsComponent 2)QuestionsComponent

@Singleton
@Subcomponent(modules = arrayOf(QuestionsModule::class))
interface QuestionsComponent {
    fun inject(questionsActivity: QuestionsActivity)
}

Modules: 模块:

1) AppModule 1)AppModule

@Module
class AppModule(val application: Application) {

    @Provides
    @Singleton
    fun provideApplication(): Context = application

    @Provides
    @Singleton
    fun provideSharedPrefs(context: Context): SharedPreferences =
            context.getSharedPreferences(context.packageName, Context.MODE_PRIVATE)
}

2) QuestionsModule 2)QuestionsModule

@Module
class QuestionsModule {
    @Provides @Singleton
    fun provideQuestionsPresenter(questionsInteractor: QuestionsInteractor): QuestionsPresenter =
        QuestionsPresenter(questionsInteractor)

    @Provides @Singleton
    fun provideQuestionsInteractor(api : Api): QuestionsInteractor = QuestionsInteractor(api)
}

App: 应用程式:

class App : Application() {
    val appComponent: AppComponent by lazy {
        DaggerAppComponent.builder()
            .netModule(NetModule())
            .appModule(AppModule(this))
            .build()

    }

    val questionsComponent: QuestionsComponent by lazy {
        appComponent.plus(QuestionsModule())
    }

    override fun onCreate() {
        super.onCreate()
        Injector.inject(this)
        NetUtils.init(this)
    }
}

If it helps then I attach a link to the githab 如果有帮助,那么我将链接附加到githab

You've defined both AppComponent and QuestionsComponent as @Singleton , so which one is responsible for that scope? 您已经定义都AppComponentQuestionsComponent@Singleton ,所以哪一个是负责该范围是什么? That is exactly what the error says. 这正是错误所说的。 Remove the annotation from one of them. 从其中之一中删除注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM