由于某些原因,我正在为我的 Android 应用程序开发注释处理器以生成扩展 RealmObject
并使用 @RealmClass
和 @PrimaryKey 进行注释的类
。我假设 Realm 将从我的处理器生成的类中生成接口(interface)和中介代码。但它不起作用。
// Generated in app/build/generated/source/apt/debug/com/test/RealmRecord.java
// package and imports
@RealmClass
public class RealmRecord extends RealmObject {
@Primary
long id;
String content;
// getters and setters
}
我发现在我的 Android Studio 环境中,注释处理器似乎没有搜索 app/build/generated/source/apt/xxx 中的文件...所以 Realm 的处理器找不到我的类和进一步处理..
任何建议将不胜感激!
最佳答案
这是 Realm 注释处理器中的一个错误。参见 this line :
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
// Don't run this processor in subsequent runs. We created everything in the first one.
if (hasProcessedModules) {
return CONSUME_ANNOTATIONS;
}
...
// more buggy code down there
}
他们的处理器违反了注释处理契约(Contract):他们没有在每一轮中增量处理新文件,而是在第一轮后放弃处理。
关于android - 注解处理时从/src和/build中扫描源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42487007/