在“注释处理器”中为生成的类指定路径

我正在创建一个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(); } 

我的问题是

我可以为生成的类指定一个目录吗?

现在他们在build / source / apt文件夹中,我想在另一个源文件夹中生成它们,以便在开发过程中使它们可见。 现在,我使用DexFile来找到这个类,但在新的AndroidStudio与InstanseRun或当我使用Kotlin或任何其他随机情况DexFile停下来收集我生成的类。