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

Android编译报错::app:compileDebugJavaWithJavac任务执行失败求助

Android构建失败问题及解决方案

错误详情

  • 构建状态:失败,构建过程出现异常
  • 失败任务::app:compileDebugJavaWithJavac

无法计算任务':app:compileDebugJavaWithJavac'的属性'options.generatedSourceOutputDirectory'的值。
在任务':app:compileDebugJavaWithJavac'完成前查询映射值map(java.io.File property(org.gradle.api.file.Directory, property(org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultFilePropertyFactory$FixedDirectory, C:\Users\saura\AndroidStudioProjects\FutsalNepal\app\build\generated\ap_generated_sources\debug\out))) org.gradle.api.internal.file.DefaultFilePropertyFactory$ToFileTransformer@63c94fba)是不被支持的

项目配置文件

app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"

android {
    compileSdkVersion 32
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.androiddevs.mvvmnewsapp"
        minSdkVersion 21
        targetSdkVersion 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.material:material:1.3.0-alpha03'

    // 架构组件
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"

    // Room
    implementation "androidx.room:room-runtime:2.2.5"
    kapt "androidx.room:room-compiler:2.2.5"

    // Room的Kotlin扩展与协程支持
    implementation "androidx.room:room-ktx:2.2.5"

    // 协程
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5'

    // 协程生命周期作用域
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.6.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
    implementation "com.squareup.okhttp3:logging-interceptor:4.5.0"

    // 导航组件
    implementation "androidx.navigation:navigation-fragment-ktx:2.2.1"
    implementation "androidx.navigation:navigation-ui-ktx:2.2.1"

    implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-rc02'
    implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-rc02'

    // Glide
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    kapt 'com.github.bumptech.glide:compiler:4.11.0'
}

settings.gradle

pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        google()
        mavenCentral()
    }
}
rootProject.name = "Futsal Nepal"
include ':app'

解决步骤

1. 移除冲突的导航依赖

项目中同时引入了AndroidX版本和旧版Arch导航库,会引发依赖冲突,直接导致构建错误。删除dependencies块中的以下两行:

implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0-rc02'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0-rc02'

2. 统一版本兼容性

  • 将buildToolsVersion更新为与compileSdkVersion 32匹配的版本:
    buildToolsVersion "32.0.0"
    
  • 更新核心AndroidX库至稳定版本,避免旧版本兼容性问题:
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.core:core-ktx:1.10.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.google.android.material:material:1.9.0'
    

3. 清理构建缓存并重建

  • 重启Android Studio并清理缓存:File > Invalidate Caches... > Invalidate and Restart
  • 执行清理构建命令:终端运行./gradlew clean build,或点击工具栏的Clean Project后再点击Rebuild Project

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 23:24:31