未解决的参考:使用kapt时,Kotlin需要清理后的2个构建版本才能拾取代码 [英] Unresolved reference: Kotlin needs 2 builds after clean to pick up code when using kapt

查看:163
本文介绍了未解决的参考:使用kapt时,Kotlin需要清理后的2个构建版本才能拾取代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的Android应用中,我们使用 DBFlow 来访问SQLite数据库.我们通过Kotlin引用了DBFlow生成的类.我们已经意识到以下事实:由于代码生成无法正常工作,因此我们拥有Java中的模型类和数据库类在Kotlin中编写这些类时.

In our Android app we're using DBFlow to access the SQLite database. We're referencing the classes generated by DBFlow via Kotlin. We are already aware of the fact that we have the model classes as well as the database class in Java as code generation won't work when writing these classes in Kotlin.

但是,在每个项目清理之后,我们仍然必须两次构建代码.在设备上执行第一个构建会导致看似随机的Kotlin类产生ClassNotFoundExceptions(即使它们不访问DBFlow生成的代码或我们定义的任何模型类).启用Proguard时,编译时已经报告了同样的情况,这当然会使构建失败.第二个构建总是成功.

However we still have to build the code twice after every project clean. Executing the first build on a device results in ClassNotFoundExceptions for seemingly random Kotlin classes (even if they don't access code generated by DBFlow or any of the model classes defined by us). The same is reported already at compile time when enabling Proguard which of course fails the build. The second build always succeeds.

有趣的是,代码生成在第一次运行时就已经可以工作了-这些类在那里,IDE也可以选择它们.但是编译器以某种方式找不到它们,使我认为代码生成在构建过程中发生得太迟了.另一方面,如上所述,也没有找到不需要对代码生成和/或注释处理进行任何处理的类.

The funny thing is, that code generation already works at the first run - the classes are there and are also picked up by the IDE. But the compiler somehow can't find them making me think that the code generation happens too late in the build process. On the other hand as explained above there are also classes not found which don't have to do anything with code generation and/or annotation processing.

因此,比第二个版本有更好的解决方案吗?

So is there a better solution to this problem than a second build?

作为参考,我们应用程序build.gradle的相关部分如下所示-就像 DBFlow文档一样提示:

For reference, the relevant parts of our app's build.gradle looks like this - just like the DBFlow documentation is suggesting:

def dbflow_version = "3.0.0-beta4"

dependencies {
    kapt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
    compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"
}

kapt {
   generateStubs = true
}

编辑:我发现我对代码所做的每一次更改都必须重新构建两次.如果我以前不清理,它可以在第一个版本中正确编译,但是所做的更改根本不会被提取.

I found that I also have to rebuild twice for every change I make to the code. It compiles correctly in the first build if I didn't clean before, but the changes simply aren't picked up.

推荐答案

如果您使用kotlin和retrolambda,则可能会解决此问题:

If you use kotlin and retrolambda this might fix it:

me.tatarka:gradle-retrolambda:3.4.0

github gist

这篇关于未解决的参考:使用kapt时,Kotlin需要清理后的2个构建版本才能拾取代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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