ERROR:error.NonExistentClass Kotlin在多模块Dagger项目中 [英] ERROR : error.NonExistentClass Kotlin In multi module Dagger project

查看:206
本文介绍了ERROR:error.NonExistentClass Kotlin在多模块Dagger项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Dagger 2和Kotlin进行Android开发. 我的项目也是一个多模块项目. 我的settings.gradle文件是这样的:

I'm using Dagger 2 and Kotlin for Android development. My project is also a multi-module project. My settings.gradle file is like this:

include :app
include :lib

我还在维护lib模块.

I'm also maintaining the lib module.

在Dagger文件中(例如在组件中),我尝试从其他模块获取该项目.例如:

In the Dagger Files (for example in the component), I try to get the item from other module. For example:

@Component
interface AppComponent{
    fun getPresenter() : Presenter
}

Presenter对象在lib模块中定义.我在Linux环境中工作,并且正在使用Android Studio 3预览版Canary5.代码运行良好,并且能够生成APK.

The Presenter object is defined in lib module. I was working in linux environment and I'm using Android Studio 3 preview canary 5. The code is working well and I am able to generate APK.

但是我公司想使用稳定版的Android Studio生成APK.我正在使用Android Studio 2.3.3.

But my company wanted to generate the APK using stable version of Android Studio. I'm using Android Studio 2.3.3.

在编译Android项目时,我遇到此错误:

When compiling the Android Project, I encountered this error:

error: error.NonExistentClass

:app:kaptDebugKotlin 

是由匕首类执行并导致的,找不到该类,该类在另一个项目中定义.可能的解决方法是什么?对不起,我的英语不好.

is performed and caused by the dagger class cannot found, the class is defined in the other project. What can be the possible workaround for this? Sorry for my bad English.

推荐答案

根本原因

基本上,在使用kapt 时,无法完成很多修复工作.引用此链接,该链接解决了另一个使用pre -处理器(OrmaDatabase):

The Root Cause

Basically, there's not much that can be done to fix this when using kapt. To quote this link that tackles the same problem in another library that uses pre-processors (OrmaDatabase):

由于Kotlin会在Java注释处理运行之前进行存根处理, Kotlin对OrmaDatabase一无所知, 存根中的声明将是error.NonExistentClass.这打破了 注释处理工具.这是一种kapt限制

Because Kotlin makes its stubs before Java Annotation Processing runs, Kotlin knows just nothing about OrmaDatabase, and the name of the declaration in stubs will be error.NonExistentClass. This breaks the Annotation Processing tool. It's a kind of kapt limitation

如何修复(解决方法)

只需使用普通的aptannotationProcessor即可运行Dagger编译器.一旦我改变:

How to fix it (the workaround)

Just use plain apt or annotationProcessor for running Dagger compiler. As soon as I changed:

kapt libs.daggerCompiler

annotationProcessor libs.daggerCompiler

在模块级别build.gradle文件中的

,我能够得到错误.修复错误后,您必须将行还原为kapt,因为否则将不会生成匕首类,因为它们是在Kotlin中定义的.

in my module level build.gradle file, I was able to get the errors. After you've fixed the errors, you gotta revert the line back to kapt because otherwise dagger classes wouldn't be generated since they're defined in Kotlin.

这篇关于ERROR:error.NonExistentClass Kotlin在多模块Dagger项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆