当前位置: 首页 > 知识库问答 >
问题:

无法在Android kotlin项目中使用本地批注处理器

耿星雨
2023-03-14

我有一个AS3/gradle plugin 3项目,我们最近在其中引入了一个本地简单的注释处理器。适用于gradles annotationProcessor Dependency指令。

我开始添加Kotlin代码,并将所有annotationProcessor指令移动到kapt指令。Glide和logan square对Kotlin使用注释处理器没有问题,但我们当地的AP项目无法由kapt执行:

:app:kaptGenerateStubsDebugKotlin
Using Kotlin incremental compilation

e: java.util.ServiceConfigurationError: javax.annotation.processing.Processor: Error reading configuration file
    at java.util.ServiceLoader.fail(ServiceLoader.java:232)
    at java.util.ServiceLoader.parse(ServiceLoader.java:309)
    at java.util.ServiceLoader.access$200(ServiceLoader.java:185)
    at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:357)
    at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
    at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
    at kotlin.collections.CollectionsKt___CollectionsKt.toCollection(_Collections.kt:1042)
    at kotlin.collections.CollectionsKt___CollectionsKt.toMutableList(_Collections.kt:1075)
    at kotlin.collections.CollectionsKt___CollectionsKt.toList(_Collections.kt:1066)
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.loadProcessors(Kapt3Extension.kt:92)
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:160)
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:82)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:96)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:106)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:83)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:377)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:68)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:96)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:368)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:133)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:154)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:58)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:103)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:51)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:92)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:303)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:85)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:213)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:37)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:74)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:87)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.execIncrementalCompiler(CompileServiceImpl.kt:512)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execIncrementalCompiler(CompileServiceImpl.kt:96)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:399)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:889)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:96)
    at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:916)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:888)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:398)
    at sun.reflect.GeneratedMethodAccessor87.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:346)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: JAR entry META-INF/services/javax.annotation.processing.Processor not found in /Users/kread/git/bgo/myrmecophaga-2.0/ejecta-v8/v8annotations-compiler/build/libs/v8annotations-compiler.jar
    at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:144)
    at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:152)
    at java.net.URL.openStream(URL.java:1045)
    at java.util.ServiceLoader.parse(ServiceLoader.java:304)
    ... 55 more


:app:kaptGenerateStubsDebugKotlin FAILED

创建的JAR文件有必要的META-INF JAR条目:

# jar tf /Users/kread/git/bgo/myrmecophaga-2.0/ejecta-v8/v8annotations-compiler/build/libs/v8annotations-compiler.jar
META-INF/
META-INF/MANIFEST.MF
ag/
ag/boersego/
ag/boersego/v8annotations/
ag/boersego/v8annotations/compiler/
ag/boersego/v8annotations/compiler/V8AnnotationProcessor$1.class
ag/boersego/v8annotations/compiler/V8AnnotationProcessor$AccessorTuple.class
ag/boersego/v8annotations/compiler/V8AnnotationProcessor$AnnotationHolder.class
ag/boersego/v8annotations/compiler/V8AnnotationProcessor.class
META-INF/services/
META-INF/services/javax.annotation.processing.Processor

摘自主模块构建。格雷德尔:

dependencies {
    // gazillions of compile / api / ...
    api project(':ejecta-v8:v8annotations')
    kapt project(':ejecta-v8:v8annotations-compiler')
}

模块V8C构建。格雷德尔:

apply plugin: 'java-library'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {}

模块v8annotations编译器构建。格雷德尔:

apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    compile project(':ejecta-v8:v8annotations')
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

我被难住了:(

共有3个答案

郗奇玮
2023-03-14

这对我有用

pkill gradle 
clean project 
make project
黄高爽
2023-03-14

就我而言,这足以让我逃跑

gradlew --stop

从AndroidStudio控制台

范稳
2023-03-14

我有过好几次类似的问题。我尝试了两种方法的结合

pkill gradle
pkill java

以及删除的android studio设置。创意/工作空间。xml和*。iml文件。这似乎是导致此问题的缓存状态。

 类似资料:
  • 我试图使用IntelliJ2017 Ultimate构建/运行一个使用MapStruct的Spring Boot应用程序。这是一个分级项目。我的问题是IntelliJ似乎没有运行MapStruct注释处理器。我意识到我可以配置IntelliJ来委托Gradle构建过程(请参见此),但我希望简单地配置IntelliJ来使用APT来生成必要的类本身。 我已经为我的项目启用了APT,但是我的类仍然没有生

  • 我是一个初学者,刚刚开始学习Spring Batch。我在这里按照这个教程创建了一个helloworld示例。当我按照教程操作时,我在尝试将导入java类时遇到了一个问题。因此我在网上搜索,发现我需要在build.gradle.中添加一些东西。问题是,即使我在build.gradle中添加了依赖项,我仍然有导入的错误消息。我正在使用EclipseJavaEE IDE 4.5.0(Mars)来完成这

  • 我正在将一个java项目从weblogic 8.1迁移到weblogic 12c。 根据甲骨文文档,我已经转换了以下内容。 在所有这些更改之后,生成war文件并部署在weblogic 12c服务器中,该服务器会产生如下错误 代码:

  • 我正在尝试通过批处理文件创建vbs。但是有一行我包含一个对象。批处理文件无法将闭括号 )写入vbs,这在运行vbs时会导致错误。 批处理文件代码为: 输出: vbs zipIt.vbs vbs输出:Microsoft (R) Windows Script Host版本5.8版权所有(C) Microsoft Corporation。保留所有权利。 C: \Users\arvind\Desktop\

  • 我正在尝试实现一个Spring批处理作业,为了处理记录,它需要2-3个db调用,这会减慢记录的处理速度(大小为100万)。如果我使用基于块的处理,它会单独处理每条记录,性能会很慢。因此,我需要一次性处理1000条记录,作为批量处理,这将减少数据库调用,并提高性能。但我的问题是,如果我实现Tasklet,那么我也会失去可重启性和重试/跳过功能,如果使用AggregateInputReader实现,我

  • 我正在编写自己的注释处理器,我希望能够注释函数的返回类型。 下面是注释的代码: 以及来自注释处理器的部分代码: 当我尝试编译代码时,出现以下异常: