Execution failed for task ‘:app:kaptDebugKotlin‘.

文章描述了在M1芯片的Mac电脑上,新工程项目遇到Room与SQLite-JDBC不兼容的问题,导致编译错误。解决方案包括修改依赖排除特定库,或者使用JDK的x86/x64版本和Rosetta。目前有一个未发布的pullrequest在GitHub上支持AppleSilicon,期待在后续版本中得到解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我的场景:

1.Mac电脑,M1芯片
2.新工程项目,没有任何改动

报错:

在这里插入图片描述

解决办法

在Google的IssueTracker里找到的
总结:room没有适配M1,需要对room的引用进行修改

kapt("org.xerial:sqlite-jdbc:3.34.0") //追加这条
kapt("androidx.room:room-compiler:2.3.0-beta01")

或者

 def room_version = "2.3.0-alpha03"
    implementation("androidx.room:room-runtime:$room_version") {
        exclude(group:'org.xerial')
    }
    kapt("androidx.room:room-compiler:$room_version"){
        exclude(group:'org.xerial')
    }
    implementation("androidx.room:room-ktx:$room_version"){
        exclude(group:'org.xerial')
    }
    implementation 'org.xerial:sqlite-jdbc:3.34.0'

原因:

大佬的回复:

大佬A:
Room uses https://github.com/xerial/sqlite-jdbc a JDBC library for SQLite, can you please file a bug in https://github.com/xerial/sqlite-jdbc asking to support the aarch64 architecture in the new Mac + M1 Chip?

I don’t have a M1 machine to try this out but my guess is they simply don’t have yet a compiled SQLite native lib for the aarch64.

大佬A:
By the way, I imagine you can workaround this using a JDK x86/x64 version + Rosetta that would make the JNI layer load the right native library.

大佬B:
Yes, Apple Silicon is supported by this pull request https://github.com/xerial/sqlite-jdbc/pull/558, but not released yet.

Hope to be supported in the next version of Room. Thanks!

在Android开发过程中,我们经常会遇到一些错误和问题。其中一个常见的问题是在构建应用程序时出现"execution failed for task ':app:kaptdebugkotlin'. > a failure occurred while"的错误信息。 这个错误通常是由于Kotlin Annotation Processing Tool (KAPT)出现问题导致的。KAPT是一个用于处理Kotlin注解的工具,它可以帮助我们在编译期间生成一些代码。当我们在项目中使用了一些需要处理的注解时,KAPT会尝试进行代码生成。 然而,有时候KAPT在处理注解时可能会出错。这可能是由于注解的定义不正确、注解处理器的问题、依赖冲突或其他原因引起的。当KAPT出现错误时,Gradle会抛出"execution failed for task ':app:kaptdebugkotlin'. > a failure occurred while"的错误信息。 要解决这个问题,我们可以尝试以下几个步骤: 1. 检查项目中使用的所有注解,并确保它们的定义是正确的。有时候注解的参数、类型或其他属性不正确可能导致KAPT出错。 2. 检查项目中使用的注解处理器,并确保它们是最新版本。有些注解处理器可能存在Bug或与其他依赖项冲突,导致KAPT出错。 3. 通过查看Gradle的日志输出,定位错误的原因。Gradle通常会提供更详细的错误信息,帮助我们找出问题所在。 4. 更新Gradle和Android Gradle插件的版本。有时候旧版本的Gradle或插件可能存在Bug,升级到最新版本可能有助于解决问题。 5. 检查项目的依赖项,确保没有版本冲突或不兼容的库。有时候不同库之间的版本冲突可能导致KAPT出错。 通过以上几个步骤,我们可以尝试解决"execution failed for task ':app:kaptdebugkotlin'. > a failure occurred while"的错误信息。如果问题仍然存在,我们可以尝试在开发者社区或相关论坛上寻求帮助,寻找其他解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值