Kotlin ARouter 集成错误记录

Kotlin ARouter 集成错误记录

先写结论:

在module的 build.gradle文件中添加

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-kapt'

apply plugin: 'kotlin-android-extensions'

 

kapt {

arguments {

arg("AROUTER_MODULE_NAME", project.getName())

}

}

 

implementation 'com.alibaba:arouter-api:1.4.0'

kapt 'com.alibaba:arouter-compiler:1.2.1'

 

遇到的错误

1、Parallel execution is an incubating feature.

FAILURE: Build failed with an exception.

* Where:

Build file 'D:\gitcode\passwordBook\app\build.gradle' line: 29

* What went wrong:

A problem occurred evaluating project ':app'.

> Could not find method kapt() for arguments [build_d4yy1frgwng0whnkzk3q3207o$_run_closure1$_closure6@1d2a6844] on object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

CONFIGURE FAILED in 1s

Could not find method kapt() for arguments [build_d4yy1frgwng0whnkzk3q3207o$_run_closure1$_closure6@1d2a6844] on object of type com.android.build.gradle.internal.dsl.BaseAppModuleExtension.

Open File

 

问题原因:没有配置好kapt

解决:添加apply plugin: 'kotlin-kapt'

 

错误2

Task ':app:kaptDebugKotlin' is not up-to-date because:

No history is available.

i: 注: ARouter::Compiler >>> AutowiredProcessor init. <<<

w: 警告: 来自注释处理程序 'org.jetbrains.kotlin.kapt3.base.ProcessorWrapper' 的受支持 source 版本 'RELEASE_7' 低于 -source '1.8'

e: 错误: ARouter::Compiler An exception is encountered, [These no module name, at 'build.gradle', like :

apt {

arguments {

moduleName project.getName();

}

}

]

e: [kapt] An exception occurred: java.lang.RuntimeException: ARouter::Compiler >>> No module name, for more information, look at gradle log.

at com.alibaba.android.arouter.compiler.processor.InterceptorProcessor.init(InterceptorProcessor.java:104)

at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.init(annotationProcessing.kt)

at com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.(JavacProcessingEnvironment.java:500)

at com.sun.tools.javac.processing.JavacProcessingEnvironment$DiscoveredProcessors$ProcessorStateIterator.next(JavacProcessingEnvironment.java:597)

at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:690)

at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)

at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)

at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)

at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)

at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1068)

at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:55)

at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:27)

at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:218)

at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:183)

at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:100)

at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:95)

at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:105)

at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:82)

at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:375)

at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:67)

at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)

at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:366)

at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:120)

at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:161)

at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:57)

at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:96)

at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.java:52)

at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:93)

at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:442)

at org.jetbrains.kotlin.daemon.CompileServiceImpl$compile$1$1$2.invoke(CompileServiceImpl.kt:102)

at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:1029)

at org.jetbrains.kotlin.daemon.CompileServiceImpl$doCompile$$inlined$ifAlive$lambda$2.invoke(CompileServiceImpl.kt:102)

at org.jetbrains.kotlin.daemon.common.DummyProfiler.withMeasure(PerfUtils.kt:137)

at org.jetbrains.kotlin.daemon.CompileServiceImpl.checkedCompile(CompileServiceImpl.kt:1071)

at org.jetbrains.kotlin.daemon.CompileServiceImpl.doCompile(CompileServiceImpl.kt:1028)

at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:441)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

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:324)

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)

 

问题原因:没有配置annotationProcressor

解决:

kapt {

arguments {

arg("AROUTER_MODULE_NAME", project.getName())

}

}

注:这个问题搜了一堆文档,很多人写的是

kapt {

    arguments {

       arg("moduleNmae", project.getName())

    }

}

但是我的工程就是没法跑起来。个人猜测可能和工程的gradle、kotlin版本有关,这个有待验证。

 

错误3

AGPBI: {"kind":"error","text":"Program type already present: android.support.v4.os.ResultReceiver","sources":[{}],"tool":"D8"}

 

解决办法:

在工程的gradle.properties

中添加

android.useAndroidX=true

android.enableJetifier=true

你可能感兴趣的:(android)