error: package generated.schema does not exist
Asked Answered
K

1

0

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.
Kalikalian answered 21/6, 2019 at 6:36 Comment(2)
how do you write the file inside your processor?Shortie
@ElHoss I'm using JavaPoet, I've added the relevant code.Kalikalian
K
0

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.

Kalikalian answered 1/7, 2019 at 7:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.