error: package generated.schema does not exist

喜夏-厌秋 提交于 2019-12-24 19:18:14

问题


In my Android Application I have an annotation processor which generates files using JavaPoet and places them under the package generated.schema.

The files are generating correctly. Whenever I use the generated file like so

GeneratedFile.someGeneratedMethod();

I get the following error:

error: package generated.schema does not exist.

But if I include the fully qualified class name instead of importing like so

generated.schema.GeneratedFile.someGeneratedMethod();

the code compiles and runs without any error.

I don't want to add complete package each time I am using GeneratedFile. I'm not sure what I did wrong, since I'm still learning to work with Annotation Processor.

Files generated by other libraries including Realm, DataBinding are all working correctly as expected.

File Generation :

using JavaPoet I run the following code.

if (roundEnvironment.processingOver()) {
    for (TypeElement element : apiList) {
        TypeSpec clazz = generateFile(element);

        JavaFile.builder(NamespaceCreator.generateClassPackage(element), clazz)
                .build()
                .writeTo(filer);
    }
}
  • NamespaceCreator.generateClassPackage(element) returns the package name for class i.e generated.schema.

回答1:


While generating classes I was waiting for the last processing pass. the code generation encapsulated by

if (roundEnvironment.processingOver())

I was getting a warning because of this:

File for type 'generated.schema.GeneratedFile' created in the last round will not be subject to annotation processing.

I was aware of this warning before I posted the question, however I was willing to ignore further annotation processing on my generated files for simplicity of generating all files in one go.

Even though, after removing the last round/pass check from file generation I can correctly (with import) access the generated files without any error; I still don't understand how generating files throughout all rounds affects accessing files during build with import.

For that I will be posting a new question.



来源:https://stackoverflow.com/questions/56698084/error-package-generated-schema-does-not-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!