我正在创建一个 Android 应用程序。我使用 AbstractProcessor 从 Annotated 类和 Velocity 模板生成我自己的类。
这是生成源文件的方法。
private void createSourceFile(String className, String packageName,
VelocityContext context, Template template) throws IOException {
final JavaFileObject javaFileObject =
processingEnv.getFiler().createSourceFile(packageName + "." + className);
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "creating file: " + javaFileObject.toUri());
final Writer writer = javaFileObject.openWriter();
if (DEBUGGING) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "applying velocity template: " + template.getName());
}
template.merge(context, writer);
writer.close();
}
Run Code Online (Sandbox Code Playgroud)
我的问题是
现在它们在build/source/apt文件夹中,我想在另一个源文件夹中生成它们,以使它们在开发过程中可见。现在我DexFile
用来查找这些类,但是在带有 InstanseRun 的新 AndroidStudio 中,或者当我使用 Kotlin 或任何其他随机情况时,DexFile 会停止收集我生成的类。