- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我长期以来一直遇到这个问题:我无法在 Android Studio 中的应用程序中升级 gradle 版本和 kotlin gradle 插件,我能想到的唯一解决方案是从头开始一个项目并逐个移动每堂课一个。
我的应用程序使用 Room,因此使用 kapt 作为注释过程。使用此版本的 kotlin 和 gradle 一切都可以完美运行:
classpath 'com.android.tools.build:gradle:4.0.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50'
我的应用程序 gradle 文件
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
//Kapt is the annotation processor of kotlin, all the generated code Ex. @Room depends of it
apply plugin: 'kotlin-kapt'
kapt {
generateStubs = true
correctErrorTypes = true
mapDiagnosticLocations = true
javacOptions {
// Increase the max count of errors from annotation processors.
// Default is 100.
option("-Xmaxerrs", 700)
}
}
android {
signingConfigs {
Default {
...
}
}
compileSdkVersion 29
defaultConfig {
applicationId "com.android.expenses"
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.Default
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation":
"$projectDir/schemas".toString()]
}
}
}
sourceSets {
// Adds exported schema location as test app assets.
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
buildTypes {
debug {
....
}
release {
....
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
//To avoid duplicate class clash
exclude group: 'com.google.guava', module: 'listenablefuture'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
//Para parcelize y autobinding in kotlin
androidExtensions {
experimental = true
}
kotlinOptions {
jvmTarget = '1.8'
}
//De databinding, y kotlinx
/*dataBinding {
enabled = true
}*/
//Substitule to 3 line above with this
android.buildFeatures.dataBinding true
}
dependencies {
//version definition
def room_version = "2.2.5"
implementation fileTree(include: ['*.jar'], dir: 'libs')
//androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
// exclude group: 'com.android.support', module: 'support-annotations'
//})
testImplementation 'junit:junit:4.12'
// Required for instrumented tests
androidTestImplementation 'com.android.support:support-annotations:28.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
//Architecture
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.core:core:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'joda-time:joda-time:2.7'
implementation 'org.joda:joda-money:0.10.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.neovisionaries:nv-i18n:1.15'
implementation 'de.hdodenhof:circleimageview:2.2.0'
//ColorPicker
implementation 'com.jaredrummler:colorpicker:1.1.0'
//Image Cropper
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
// Google Sheet API y Google Drive
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'pub.devrel:easypermissions:3.0.0'
implementation('com.google.api-client:google-api-client-android:1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
// Google Sheet API
implementation('com.google.apis:google-api-services-sheets:v4-rev504-1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
// Google Drive Rest
implementation('com.google.apis:google-api-services-drive:v3-rev102-1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
//Google Drive Android
implementation "com.google.android.gms:play-services-drive:$rootProject.playServices_version"
//Google Maps
implementation "com.google.android.gms:play-services-location:$rootProject.playServices_version"
implementation 'com.google.android.gms:play-services-maps:16.1.0'
//Google Maps Utils
implementation 'com.google.maps.android:android-maps-utils:0.5'
//Google Places
implementation "com.google.android.gms:play-services-places:$rootProject.playServices_version"
//MultiViewAdapter para mejores recyclerviews
implementation 'com.github.devahamed:multi-view-adapter:1.2.6'
implementation 'com.github.devahamed:multi-view-adapter-databinding:1.2.6'
//CardView
implementation 'androidx.cardview:cardview:1.0.0'
//PagerSlidingTabStrip
implementation 'com.jpardogo.materialtabstrip:library:1.1.1'
//Room
implementation "androidx.room:room-runtime:$room_version"
//annotationProcessor "androidx.room:room-compiler:$room_version"
// optional - Kotlin Extensions and Coroutines support for Room
//implementation "androidx.room:room-ktx:$room_version"
// Test helpers
androidTestImplementation "androidx.room:room-testing:$room_version"
kapt "androidx.room:room-compiler:$room_version"
// Lifecycle components
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.3.1'
kapt 'androidx.lifecycle:lifecycle-compiler:2.3.1'
//Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9")
// RxJava support for Room
implementation 'androidx.room:room-rxjava2:2.0.0'
//Android Palette API
implementation 'androidx.palette:palette:1.0.0'
//Welcome Activity
implementation 'com.github.AppIntro:AppIntro:6.1.0'
//Charts
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
//TableView
implementation 'com.evrencoskun.library:tableview:0.8.8'
//Anko Commons Library for easier development
implementation "org.jetbrains.anko:anko-commons:$anko_version"
//Search Dialog
implementation 'com.github.mirrajabi:search-dialog:1.2.4'
//FAB Button Speed Dial
implementation 'com.leinardi.android:speed-dial:3.2.0'
//WorkManager
implementation('androidx.work:work-runtime-ktx:2.0.1') {
exclude group: 'com.google.guava', module: 'listenablefuture'
}
//PagingList
implementation 'androidx.paging:paging-runtime:2.1.0'
//Calendar
implementation 'com.github.prolificinteractive:material-calendarview:2.0.1'
//Image Compressing
implementation 'id.zelory:compressor:3.0.1'
//New Places: Old one is deprecated
implementation 'com.google.android.libraries.places:places:2.4.0'
// Koin for Android
implementation 'org.koin:koin-android:2.0.0-rc-2'
implementation 'org.koin:koin-android-viewmodel:2.0.0-rc-2'
// KTX
implementation 'androidx.core:core-ktx:1.3.2'
// Rx
implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
// Moshi
implementation 'com.squareup.moshi:moshi:1.8.0'
kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.8.0'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.1'
// Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
//SQLCipher
implementation "net.zetetic:android-database-sqlcipher:4.4.0@aar"
....
}
repositories {
mavenCentral()
}
// For Firebase
apply plugin: 'com.google.gms.google-services' // Google Play services Gradle plugin
我尝试更新到每个版本的当前最新版本,尽管这个问题存在于不太新的版本中
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20'
为了进行此更改,我执行了以下操作:
尽管如此,我仍然遇到这个错误
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
> java.lang.reflect.InvocationTargetException (no error message)
* 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.
app:kaptDebugKotlin 下面有消息,但它们是非 @Entity 类的多个构造函数的警告,不应引发崩溃
这真的很令人沮丧,因为我不知道还能做什么或如何获取更多信息(我也使用 --info 进行了运行,但我只从 kapt 得到相同的输出)
预先感谢您的时间和帮助
更新
这是我的最高等级
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
//ext.kotlin_version = '1.4.10'
//Working version
ext.kotlin_version = '1.3.50'
//Latest version
//ext.kotlin_version = '1.5.20'
//ext.kotlin_version = '1.3.41'
repositories {
mavenCentral()
google()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
//jcenter()
}
dependencies {
// working version, if change modify distributionUrl in gradle-wrapper.properties
classpath 'com.android.tools.build:gradle:4.0.2'
// to upgrade
//classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
//De MaterialChipsInput y Search Dialog
maven {
url "https://jitpack.io"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext{
archLifecycleVersion = '1.1.1'
anko_version='0.10.5'
support_version = '28.0.0'
playServices_version = '16.0.0'
}
快速更新,当我尝试仅将房间版本升级到2.3.0时出现错误:
[kapt] An exception occurred: java.lang.NoSuchMethodError: kotlin.jvm.internal.FunctionReferenceImpl.<init>(ILjava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
at androidx.room.log.RLog$CollectingMessager$writeTo$printMessage$1.<init>(RLog.kt)
at androidx.room.log.RLog$CollectingMessager.writeTo(RLog.kt:92)
at androidx.room.solver.TypeAdapterStore.findRowAdapter(TypeAdapterStore.kt:520)
at androidx.room.solver.TypeAdapterStore.findQueryResultAdapter(TypeAdapterStore.kt:459)
at androidx.room.solver.binderprovider.InstantQueryResultBinderProvider.provide(InstantQueryResultBinderProvider.kt:29)
at androidx.room.solver.TypeAdapterStore.findQueryResultBinder(TypeAdapterStore.kt:391)
at androidx.room.processor.DefaultMethodProcessorDelegate.findResultBinder(MethodProcessorDelegate.kt:140)
at androidx.room.processor.InternalQueryProcessor.getQueryMethod(QueryMethodProcessor.kt:204)
at androidx.room.processor.InternalQueryProcessor.processQuery(QueryMethodProcessor.kt:135)
at androidx.room.processor.QueryMethodProcessor$process$1.invoke(QueryMethodProcessor.kt:67)
at androidx.room.processor.QueryMethodProcessor$process$1.invoke(QueryMethodProcessor.kt:37)
at androidx.room.processor.Context.collectLogs(Context.kt:133)
at androidx.room.processor.QueryMethodProcessor.process(QueryMethodProcessor.kt:61)
at androidx.room.processor.DaoProcessor.process(DaoProcessor.kt:99)
at androidx.room.processor.DatabaseProcessor.doProcess(DatabaseProcessor.kt:100)
at androidx.room.processor.DatabaseProcessor.process(DatabaseProcessor.kt:51)
at androidx.room.DatabaseProcessingStep.process(DatabaseProcessingStep.kt:47)
at androidx.room.compiler.processing.JavacProcessingStepDelegate.process(XProcessingStep.kt:111)
at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:330)
at com.google.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:181)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt)
at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:147)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
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:79)
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:35)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:230)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:188)
at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:99)
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:81)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:555)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:82)
at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:546)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:177)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:164)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:54)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:104)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1558)
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:497)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
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$256(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)
知道为什么吗?它是否相关?
解决方案:如果有人正在寻找类似的东西,我最终重新设计了该项目,问题与 moshi kapt 有关。我将库更新到 1.12.0,一切正常
最佳答案
就我而言,当我升级“kotlin-gradle-plugin:从 1.5.31 到 1.6.10”时,我遇到了同样的问题。
我已经按照官方docs将Gradle版本升级到最新版本解决了这个问题.
在android studio中进入文件>项目结构>项目>Gradle版本这里选择最新版本的Gradel。
我认为,当我们更新“kotlin-gradle-plugin”并且其他依赖项不是最新版本时,就会发生这种情况。
另外,检查一下你的JDK版本,可以关注官方docs .
关于android - 升级 kotlin 或 gradle 时 Room kapt 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69229118/
我正在查看Kotlin Github page我注意到 Kotlin 语言本身大部分是用 Kotlin 编写的:我只是想知道,一种语言怎么可能大部分都是用它自己的语言编写的?在您可以使用正在创建的语言
我有以下非常简单的 kotlin 代码来演示中缀函数 com.lopushen.demo.presentation 包 fun main(args: Array) { print("Hello
我在 Java 中有 2 个模型类,其中一个扩展了另一个 @UseStag public class GenericMessages extends NavigationLocalizationMap
Kotlin 代码 runBlocking { flow { for (i in 0..4) { println("Emit $i")
这三个 Kotlin 插件和它们的实际作用有什么区别? plugins { id 'kotlin-android' id 'org.jetbrains.kotlin.android'
我正在为某些现有库添加 Kotlin 原生 linuxX64 目标支持。库已成功编译,但在运行测试用例时,出现以下运行时错误: kotlin.native.concurrent.InvalidMuta
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 2 年前。 Improve t
我创建了一个类并向其添加了一个与成员函数具有相同签名的扩展,并执行了这个方法,它总是执行成员方法。 class Worker { fun work() = "...working" } fun
我知道传递给函数的参数将被视为“val”,即使变量被初始化为“var”。但这对我来说一直是个问题。在下面的示例代码中,我想通过使用函数“changeNum”修改变量“num”的值。但当然,Kotlin
现在,我正在尝试用 Kotlin 重写我的 Java 应用程序。然后,我遇到了日志语句,比如 log.info("do the print thing for {}", arg); 所以我有两种方法可
有点出名article关于许多语言的异步编程模型的状态,指出它们存在“颜色”问题,特别是将生态系统分为两个独立的世界:异步和非异步。以下是这种语言的属性: 每个函数都有一种颜色,红色或蓝色(例如asy
因为 KDoc 文档生成引擎是 abandoned in favor of Dokka , Kotlin 文档应该称为“KDoc 注释”,还是“Dokka 注释”? 最佳答案 如所述here , KD
我想在可空对象上传递函数引用。以 Android 为例,假设我想使用 Activity#onBackPressed来自作为该事件的子级的片段。 如果我想调用这个函数,我可以很容易地做到 activit
我有一个列表 (x, y)其中y只能是 0 或 1 这样 例如: [(3, 0), (3, 1), (5, 1)] [(5, 0), (3, 1), (5, 1)] [(1, 1), (3, 1),
从强类型语言的定义来看: A strongly-typed programming language is one in which each type of data (such as intege
这不能编译的事实是否意味着它们不是一流的类型? fun foo(s: String): Int = s.length // This won't compile. val bar = foo 有没有办
如果在 Java i++是一个表达式和 i++;是一个表达式语句,分号(;) 在 Kotlin 中是可选的,是 i++ Kotlin 中的表达式或表达式语句? 最佳答案 i++是一个表达式,因为它有一
代码(如下所示)是否正确?它取自 Kotlin-docs.pdf 的第 63 页,这也是 https://kotlinlang.org/docs/reference/generics.html 的最后
我正在尝试使用 Kotlin 为 Android 的一些全局 API 解析器(检查网络连接、调用 API 并通过来自源的单个调用返回格式化数据),并且在某些时候我不得不创建一个通用类型 object就
kotlinlang 中的任务: 使用月份变量重写此模式,使其与格式 13 JUN 1992(两位数字、一个空格、一个月份缩写、一个空格、四位数字)中的日期相匹配。 答案是:val month = "
我是一名优秀的程序员,十分优秀!