无法在Android kotlin项目

时间:2017-11-10 17:01:50

标签: android-gradle kotlin kapt

我有一个AS3 / gradle插件3项目,我们最近推出了一个本地简单的注释处理器。适用于gradles annotationProcessor依赖指令。

我开始添加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

摘自主模块build.gradle:

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

模块v8annotations build.gradle:

apply plugin: 'java-library'

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {}

模块v8annotations-compiler build.gradle:

apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

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

我很难过:(

3 个答案:

答案 0 :(得分:1)

我曾多次遇到过类似的问题。我尝试了

的组合
pkill gradle
pkill java

并删除 .idea / workspace.xml * .iml 文件的android studio设置。它似乎是一个缓存状态导致了这个问题。

答案 1 :(得分:0)

在我的情况下,运行

就足够了
gradlew --stop
来自AndroidStudio控制台的

答案 2 :(得分:0)

它对我有用

pkill gradle 
clean project 
make project