2017-05-18 49 views
6

Gradle phụ thuộc:Kapt không làm việc với AutoValue trong Android Studio 3.0

compile 'com.google.dagger:dagger:2.9' 
annotationProcessor 'com.google.dagger:dagger-compiler:2.9' 
kapt 'com.google.dagger:dagger-compiler:2.9' 

provided "com.google.auto.value:auto-value:1.4.1" 
annotationProcessor "com.google.auto.value:auto-value:1.4.1" 

nhận stacktrace này:

:presentation:kaptDevDebugKotlin 
e: @AutoValue public abstract class Categories implements CategoriesModel{ 
e:              ^
e: symbol: class CategoriesModel 
e: path/Categories.java:13: error: cannot find symbol 

w: warning: The following options were not recognized by any processor: '[kapt.kotlin.generated]' 
w: 


e: org.jetbrains.kotlin.kapt3.diagnostic.KaptError: Error while annotation processing 
    at org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:90) 
    at org.jetbrains.kotlin.kapt3.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:42) 
    at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:149) 
    at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:76) 
    at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:89) 
    at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:99) 
    at org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:76) 
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.analyze(KotlinToJVMBytecodeCompiler.kt:347) 
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:104) 
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:336) 
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules(KotlinToJVMBytecodeCompiler.kt:131) 
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:165) 
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:54) 
    at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.java:178) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.execCompiler(CompileServiceImpl.kt:387) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$execCompiler(CompileServiceImpl.kt:93) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:355) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$2.invoke(CompileServiceImpl.kt:93) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$2$$special$$inlined$withValidClientOrSessionProxy$lambda$1.invoke(CompileServiceImpl.kt:784) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$2$$special$$inlined$withValidClientOrSessionProxy$lambda$1.invoke(CompileServiceImpl.kt:93) 
    at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:811) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$checkedCompile(CompileServiceImpl.kt:93) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$2.invoke(CompileServiceImpl.kt:783) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$2.invoke(CompileServiceImpl.kt:93) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.ifAlive(CompileServiceImpl.kt:971) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.ifAlive$default(CompileServiceImpl.kt:851) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:777) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.access$doCompile(CompileServiceImpl.kt:93) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1.invoke(CompileServiceImpl.kt:354) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1.invoke(CompileServiceImpl.kt:93) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.ifAlive(CompileServiceImpl.kt:971) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.ifAlive$default(CompileServiceImpl.kt:851) 
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:327) 
    at sun.reflect.GeneratedMethodAccessor168.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) 
+0

Tôi nghĩ Kotlin không cần AutoValue ở tất cả bởi vì nó có các lớp dữ liệu https://kotlinlang.org/docs/reference/data-classes.html –

+0

thử sử dụng kapt thay vì chú thíchProcessor – quiro

+2

@AntonGolovin Đây là một dự án kế thừa. –

Trả lời

8

@Geng Jiawen câu trả lời đã đi đúng hướng, tôi đã thay đổi tất cả mọi thứ để kapt

provided "com.google.auto.value:auto-value:1.4.1" 
kapt "com.google.auto.value:auto-value:1.4.1" 
kaptTest "com.google.auto.value:auto-value:1.4.1" 
compile 'com.google.dagger:dagger:2.9' 
kapt 'com.google.dagger:dagger-compiler:2.9' 
kaptTest 'com.google.dagger:dagger-compiler:2.9' 

Nhưng sau đó Tôi đã nhận được

Error:Execution failed for task ':presentation:javaPreCompileProdDebug'.

Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor. Please add them to the annotationProcessor configuration.

- auto-value-1.4.1.jar 
- auto-value-gson-0.4.6.jar 
- auto-service-1.0-rc2.jar 

Alternatively, set

android.defaultConfig.javaCompileOptions.annotationProcessorOptions .includeCompileClasspath = true

to continue with previous behavior. Note that this option is deprecated and will be removed in the future. See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

Tôi đã thêm

defaultConfig { 
    javaCompileOptions { 
     annotationProcessorOptions { 
     includeCompileClasspath false 
     } 
    } 
    } 

Chỉ sau đó nó hoạt động bình thường.

tôi muốn đề cập đến rằng sử dụng kapt tăng xây dựng thời gian trên 8-10%

+0

Điều này làm việc cho tôi, nhưng tôi lo ngại về cảnh báo không dùng nữa. Tôi có thể đặt mình vào thiên tai trong tương lai không? – AutonomousApps

2

tôi chạy vấn đề này quá. Việc sửa chữa rất dễ dàng, chỉ cần thay đổi AutoValue annotationProcessor thành kapt. Kapt tạo ra tập tin java, không phải tập tin kotlin từ quan sát của tôi. Vì vậy, chú thích ban đầuProcessor là không cần thiết. Cũng nên nhớ làm sạch dự án của bạn sau sự thay đổi này.

compile 'com.google.dagger:dagger:2.9' 
kapt 'com.google.dagger:dagger-compiler:2.9' 

provided "com.google.auto.value:auto-value:1.4.1" 
kapt "com.google.auto.value:auto-value:1.4.1" 

Di chuyển dự án hiện tại để Kotlin không phải là dễ dàng, nhưng chúng ta hãy tiếp tục cố gắng nó :)

0

Tôi vừa cố định cùng một vấn đề bằng cách loại bỏ provided 'org.glassfish:javax.annotation:10.0-b28' từ phụ thuộc của tôi.

0
defaultConfig { 
javaCompileOptions { 
    annotationProcessorOptions { 
    includeCompileClasspath true 
    } 
} 

}
trong mô-đun xây dựng gradle

Các vấn đề liên quan