错误:程序包generate.schema不存在 [英] error: package generated.schema does not exist

查看:234
本文介绍了错误:程序包generate.schema不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用程序中,我有一个注释处理器,该处理器使用JavaPoet生成文件并将其放置在generate.schema包下.

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();

我收到以下错误:

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.

我不想每次使用GeneratedFile时都添加完整的软件包.我不确定自己做错了什么,因为我仍在学习使用注释处理器.

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.

由其他库(包括Realm,DataBinding)生成的文件都可以按预期正常工作.

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

文件生成:

我使用JavaPoet运行以下代码.

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)返回class的软件包名称,即generated.schema.
    • NamespaceCreator.generateClassPackage(element) returns the package name for class i.e generated.schema.
    • 推荐答案

      在生成类时,我正在等待上一次处理.

      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:

      在上一轮创建的类型为"generated.schema.GeneratedFile"的文件将不受注释处理.

      在发布问题之前,我已经意识到了这一警告,但是为了简化一次性生成所有文件的操作,我愿意忽略对生成文件的进一步注释处理.

      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.

      尽管如此,从文件生成中删除最后一个回合/通过检查之后,我仍然可以正确(带有导入)访问生成的文件而没有任何错误;我仍然不明白在使用import进行构建时,全面生成文件如何影响访问文件.

      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.

      这篇关于错误:程序包generate.schema不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆