You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级targetSdkVersion至34后kapt构建失败求助

升级targetSdkVersion至34后kapt编译失败求助

升级应用的targetSdkVersion从30到34后,遇到如下编译错误,已经困扰一周。已升级大部分第三方库版本,检查代码未发现问题,试过多种方案都无效,求解决建议。

错误信息

Execution failed for task ':app:kaptDevelopDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)

我的配置信息

应用依赖配置

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.3.1'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
    implementation 'androidx.paging:paging-runtime-ktx:3.2.1'
//    implementation 'androidx.room:room-runtime:2.5.2'
//    annotationProcessor  'androidx.room:room-compiler:2.5.2'
    def lifecycle_version = "2.6.2"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

    def room_version = "2.5.2"
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

//
//    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
//    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.2'
//    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'

    //network call
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.19'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.11'
    implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11'

    //Carousel View
    implementation 'com.synnapps:carouselview:0.1.5'

    //view binding
    implementation 'com.jakewharton:butterknife:10.2.3'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
    kapt 'com.jakewharton:butterknife-compiler:10.2.3'

    //error log
    implementation 'com.jakewharton.timber:timber:5.0.1'

    //load image
    implementation 'com.squareup.picasso:picasso:2.71828'

    //circle image view
    implementation 'com.pkmmte.view:circularimageview:1.1'

    //firebase
//    implementation('com.crashlytics.sdk.android:crashlytics:2.10.1') {
//        transitive = true
//    }
//    implementation 'com.google.firebase:firebase-core:17.5.1'
    implementation 'com.google.firebase:firebase-analytics:21.3.0'
    implementation 'com.google.firebase:firebase-crashlytics:18.4.3'


    //check network
    implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.8'

    //buttom dialog
    implementation 'com.github.javiersantos:BottomDialogs:1.2.1'

    //video player
    def exo_player_version = "2.11.0"
//    //noinspection GradleDependency
    implementation "com.google.android.exoplayer:exoplayer-core:$exo_player_version"
//    //noinspection GradleDependency
    implementation "com.google.android.exoplayer:exoplayer-hls:$exo_player_version"
//    //noinspection GradleDependency
    implementation "com.google.android.exoplayer:exoplayer-ui:$exo_player_version"

//    implementation "androidx.media3:media3-exoplayer:1.1.1"
//    implementation "androidx.media3:media3-exoplayer-dash:1.1.1"
//    implementation "androidx.media3:media3-ui:1.1.1"

    //save instance stage
    implementation 'frankiesardo:icepick:3.2.0'
    kapt 'frankiesardo:icepick-processor:3.2.0'

    //loading progress
    implementation 'com.wang.avi:library:2.1.3'

    //in app web view
    implementation 'com.github.delight-im:Android-AdvancedWebView:v3.0.0'

    //add custom font
    implementation 'io.github.inflationx:calligraphy3:3.1.1'
    implementation 'io.github.inflationx:viewpump:2.1.1'

    //app drawer
    implementation('com.mikepenz:materialdrawer:7.0.0')
    implementation 'com.mikepenz:fontawesome-typeface:4.7.0.1@aar'

    //search view
    implementation 'com.miguelcatalan:materialsearchview:1.4.0'

    //video 16:9 layout
    implementation 'com.ritesh:ratiolayout:1.0.0'

    //toast
    implementation 'com.github.GrenderG:Toasty:1.2.5'

    //bottom navigation
    implementation 'com.aurelhubert:ahbottomnavigation:2.3.4'

    //shimmer
    implementation 'com.github.sharish:ShimmerRecyclerView:v1.3'

    //mutidex
    implementation 'androidx.multidex:multidex:2.0.1'

    //kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    //buttomsheet
    implementation 'com.github.rubensousa:bottomsheetbuilder:1.6.1'
    implementation 'androidx.media:media:1.6.0'
    implementation 'org.greenrobot:eventbus:3.3.1'

    //In-app update
    implementation 'com.google.android.play:core:1.10.3'

    //App oauth
    implementation 'net.openid:appauth:0.11.1'

    //debug lib
    debugImplementation 'com.amitshekhar.android:debug-db:1.0.1'
    def work_version = "1.0.1"
    implementation "android.arch.work:work-runtime:$work_version"

    // App's dependencies, including test
    implementation 'androidx.annotation:annotation:1.7.0'
    implementation 'com.google.android.gms:play-services-analytics:18.0.3'

    //Google billing
    implementation 'com.android.billingclient:billing:6.0.1'

    //UI Testing with Espresso
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    androidTestImplementation 'androidx.test:runner:1.5.2'
    androidTestImplementation 'androidx.test:rules:1.5.0'
    implementation 'androidx.test.espresso:espresso-idling-resource:3.5.1'

    // include espresso-intents
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.5.1'
}

gradle.properties配置

org.gradle.jvmargs=-Xmx2056m
android.defaults.buildfeatures.buildconfig=true
android.useAndroidX=true
android.enableJetifier=true
kapt.use.worker.api=false
kapt.incremental.apt=false

根目录build.gradle的classpath配置

dependencies {
        classpath 'com.android.tools.build:gradle:8.1.2'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.9'
        classpath 'com.jakewharton:butterknife-gradle-plugin:10.2.3'
        classpath 'com.google.gms:google-services:4.4.0'
    }

Gradle版本为8.0,错误截图显示内容与上述控制台错误信息一致。


可能的解决建议

  • 排查kapt相关依赖兼容性:

    • 移除重复的ButterKnife编译配置,Kotlin项目仅保留kapt 'com.jakewharton:butterknife-compiler:10.2.3'即可,删掉annotationProcessor那条。
    • 升级Room版本到2.6.1或更高,旧版本Room对Android 14的API适配不足。
    • 替换停止维护的Icepick库,改用AndroidX原生的SavedStateHandle管理状态。
  • 调整kapt编译参数:
    在gradle.properties中修改参数,获取更详细日志:

    kapt.use.worker.api=true
    kapt.incremental.apt=true
    kapt.verbose=true
    

    详细日志能定位具体是哪个注解处理器抛出的异常。

  • 升级/替换第三方库:

    • OkHttp替换为稳定版(如4.11.0),alpha版本兼容性风险高。
    • ExoPlayer升级到2.19.1及以上,或直接迁移到AndroidX Media3库,适配Android 14。
    • 替换停止维护的库:比如CircularImageView、CarouselView等,改用AndroidX组件或其他活跃维护的替代方案。
  • 清理重建项目:
    执行./gradlew clean,删除项目根目录的.gradle、app/build文件夹,再重新同步项目并编译。


内容的提问来源于stack exchange,提问作者Cashchii

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 09:57:04