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

Flutter应用编译失败:AAPT2可执行文件缺失问题求助

Fix for AAPT2 Missing Error in Flutter App Build

Hey there, sorry to hear your Flutter app's build started failing with that AAPT2 missing error—since it worked perfectly before, this is almost certainly a corrupted Gradle cache or a minor path mismatch. Let's walk through some tried-and-true fixes that should get you back up and running:

Step 1: Clear Gradle and Flutter Caches

The error points to a missing AAPT2 executable in your Gradle cache folder. Wiping this cache and rebuilding often resolves the issue:

  • Run these commands in your project root first:
    flutter clean
    flutter pub get
    
  • Then manually delete the problematic Gradle cache directory mentioned in the error: C:\Users\john\.gradle\caches\transforms-2\
  • Restart your IDE after completing these steps.

Step 2: Invalidate IDE Caches (Android Studio/IntelliJ)

IDE-level caches can sometimes get stuck and cause weird build glitches:

  • Go to File > Invalidate Caches...
  • Check the box for "Invalidate and Restart"
  • Let the IDE reload fully, then try building your app again.

Step 3: Update Android Gradle Plugin (AGP) and Kotlin Versions

Your current AGP version (3.5.0) is quite outdated, which might be causing compatibility issues with newer Flutter versions. Try updating your buildscript block to more recent stable versions (and note that JCenter is deprecated, so we'll switch to Maven Central):

buildscript {
    ext.kotlin_version = '1.7.20'
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

After updating, click "Sync Now" in the IDE to apply the changes.

Step 4: Verify Flutter and Android SDK Setup

Run flutter doctor in your terminal to check for any missing components or mismatched versions. Fix any issues it reports (like outdated build tools, missing SDK components, etc.)—this often catches hidden setup problems.


Your Original Error Details

任务':app:mergeDebugResources'执行失败。指定的AAPT2可执行文件不存在:C:\Users\john.gradle\caches\transforms-2\files-2.1\a406eb4ba72ff395bc6c8b1db90b3b1f\aapt2-3.5.0-5435860-windows\aapt2.exe。必须从Maven提供AAPT2或指定自定义路径。可尝试:使用--stacktrace选项获取堆栈跟踪;使用--info或--debug选项获取更多日志输出;使用--scan选项获取完整分析信息。更多帮助请访问https://help.gradle.org。

Your Original buildscript Config

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}
allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 15:42:31