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.
2
  • how do you write the file inside your processor?
    – El Hoss
    Jun 24, 2019 at 8:41
  • @ElHoss I'm using JavaPoet, I've added the relevant code.
    – Abbas
    Jun 24, 2019 at 8:49

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.