我刚刚更新到Android Studio Flamingo | 2022.2.1
. 现在我得到这个错误:
Execution failed for task ':app:kaptGenerateStubsDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'kaptGenerateStubsDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain
Run Code Online (Sandbox Code Playgroud)
我正在使用 AS 包含的 Kotlin,但这1.8.0
与AGP和 Gradle一起工作得很好- 它只与来自 AS Flamingo 的 Gradle 和 AGP 更新有关。还:7.4.2
7.5
1.7.20
它又可以工作了1.8.20
出现上面的错误我确实有编译选项:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
} …
Run Code Online (Sandbox Code Playgroud) 在我的app模块的build.gradle中,我添加了
dependencies {
kapt('com.android.databinding:compiler:3.1.2')
...
}
Run Code Online (Sandbox Code Playgroud)
但我仍然收到编译器警告
app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'com.android.databinding:compiler:3.1.2'.
Run Code Online (Sandbox Code Playgroud)
一切正常,我只是讨厌挂着警告.
任何帮助深表感谢!
我想知道在混合Java和Kotlin文件的Android项目中,我们必须使用annotationProcessor或kapt,还是两者兼而有之?
在我的理解中,annotationProcessor必须使用注释进行代码生成的Java文件,kapt必须使用注释生成代码来生成Kotlin文件.
我有一个混合两种语言的项目,我刚刚用kapt替换了build.gradle中的所有annotationProcessor依赖项.令人惊讶的是它构建并且似乎运行正常但我不明白为什么kapt即使使用Java文件也能正常运行...
有人可以向我解释一下吗?
谢谢
我当前的 Android 项目显示以下构建消息:-
> Task :shared:resource:kaptGenerateStubsProductionDebugKotlin
'compileProductionDebugJavaWithJavac' task (current target is 17) and 'kaptGenerateStubsProductionDebugKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
By default will become an error since Gradle 8.0+! Read more: https://kotl.in/gradle/jvm/target-validation
Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain
Run Code Online (Sandbox Code Playgroud)
如何配置 kapt 在特定版本的 java 中生成存根?
我努力了...
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KaptGenerateStubs).configureEach {
kotlinJavaToolchain.jdk.use(
"/usr/local/opt/openjdk@17/libexec/openjdk.jdk/Contents/Home",
JavaVersion.VERSION_17
)
}
Run Code Online (Sandbox Code Playgroud)
和
kapt {
javacOptions {
option("--target", 17)
}
}
Run Code Online (Sandbox Code Playgroud)
这些都没有任何区别
是否可以控制 Android 项目中 kapt 生成的存根的 java 版本?
在 kapt3 中启用详细日志记录后,我现在可以看到我已正确配置目标 …
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
classpath 'com.android.tools.build:gradle:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.61"
Run Code Online (Sandbox Code Playgroud)
我有上面的gradle配置,但我仍然得到
Could not find method kapt() for arguments [com.github.bumptech.glide:compiler:4.3.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Run Code Online (Sandbox Code Playgroud)
谁能告诉我哪里出错了?我在这里先向您的帮助表示感谢
我在我的Android项目中使用Dagger 2,但我在调试时遇到问题.我知道编译失败是因为我的匕首2设置中的错误(以前有过)但是几乎不可能跟踪它,因为我没有得到正确的错误消息告诉我问题出在哪里.我得到的只是显示注释处理失败的消息.沿着:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Error:(14, 28) error: cannot find symbol class BR
Error:(17, 40) error: package com.some.package.databinding does not exist
Error:(17, 51) error: cannot find symbol class DaggerSomeComponent
...
Run Code Online (Sandbox Code Playgroud)
也许它与某些事实有关,我也在使用数据绑定!?
我正在使用Dagger 2.5,Gradle插件2.1.2和android-apt 1.8.
谢谢你的帮助!
android annotation-processing dagger-2 android-databinding kapt
:app:kaptDebugKotlin
w: warning: The following options were not recognized by any processor: '[kapt.kotlin.generated, room.incremental]'
Run Code Online (Sandbox Code Playgroud)
为什么我得到这个?我在一个多模块项目中使用 Room。
共享库模块:
api "androidx.room:room-runtime:$room_version"
api "androidx.room:room-ktx:$room_version"
api "androidx.room:room-rxjava2:$room_version"
应用模块:
kapt "androidx.room:room-compiler:$room_version"
Gradle.properties
kapt.incremental.apt=true
Run Code Online (Sandbox Code Playgroud)
Build.gradle defaultConfig 包括这些编译选项:
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.incremental":"true"]
}
}
Run Code Online (Sandbox Code Playgroud) 我有以下项目结构
root-project
? build.gradle.kts
?
????multiplatform-project
? ? build.gradle.kts
? ?
? ????src
? ? kotlin
| | js
?
????simple-kotlin-project
? build.gradle.kts
Run Code Online (Sandbox Code Playgroud)
所以总共有 3 个项目(3 个build.gradle.kts
文件)。
这是根项目build.gradle.kts
plugins {
kotlin("jvm") version kotlinVersion apply false
kotlin("kapt") version kotlinVersion apply false
kotlin("multiplatform") version kotlinVersion apply false
}
subprojects {
apply<JavaPlugin>()
if (name.contains("multiplatform-project")) {
apply(plugin = "org.jetbrains.kotlin.multiplatform")
} else {
apply(plugin = "kotlin")
}
apply(plugin = "kotlin-kapt")
dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-M2")
implementation("org.slf4j:slf4j-api:1.7.25")
implementation("ch.qos.logback:logback-core:1.2.3")
implementation("ch.qos.logback:logback-classic:1.2.3")
testImplementation("junit:junit:$jUnitVersion")
} …
Run Code Online (Sandbox Code Playgroud)我用kapt编写了一个代码生成器,并在一个用maven编译kotlin的项目中使用它.
我发现在Kotlin的编译阶段之后调用了kapt生成器,这阻止了我在同一个项目中使用kotlin中生成的代码.
但是,如果我在同一个项目中从Java中引用生成的类,它可以正常工作.这是因为java编译阶段是在kotlin的生成阶段之后.
我已经在maven配置中的Kotlin编译目标之前指定了kapt目标(如文档中所述)但它似乎没有什么区别:
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>kapt</id>
<goals>
<goal>kapt</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/java</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>lang.taxi</groupId>
<artifactId>taxi-annotation-processor</artifactId>
<version>${taxi.version}</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
<execution>
<id>compile</id>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
是否可以配置Kotlin以允许我在同一个项目中使用Kotlin生成的代码?
我已经看过这个答案和这个网站上的其他人,并使用谷歌,但我还没有找到适合这个问题的答案。这是最新版本的 KAPT 列出的剩余的非增量注释处理器:
Incremental annotation processing requested, but support is disabled because the following processors are not incremental: android.databinding.annotationprocessor.ProcessDataBinding (NON_INCREMENTAL)
Run Code Online (Sandbox Code Playgroud)
请注意,我已迁移到 AndroidX 并使用 AGP 3.4.1(无法升级到 AGP 3.5.x)和 Gradle 5.5。任何帮助将非常感激。