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

Android Studio中Flutter项目构建报错求助(已升级gradle-version并重装AS)

Hey there, sorry to hear you're stuck with this build error in your Flutter project on Android Studio—let's work through this step by step. Since you've already tried upgrading Gradle and reinstalling Android Studio, let's dig into some other common fixes that often resolve these tricky build issues.

Common Troubleshooting Steps to Fix Flutter Build Errors in Android Studio
  • Check Flutter & Dart SDK Compatibility
    First, make sure your Flutter SDK is up to date and playing nice with your project's setup. Run these commands in your terminal:

    flutter upgrade
    flutter doctor
    

    The flutter doctor command will flag any missing components or version mismatches—pay extra attention to Android-related warnings (like missing SDK platforms, outdated build tools, or incompatible Kotlin versions). Fix any issues it highlights before moving on.

  • Invalidate Caches & Hard Restart Android Studio
    Sometimes cached data gets corrupted even after a full reinstall. Head to File > Invalidate Caches..., check all the cache boxes, and select "Invalidate and Restart". This wipes out all stale build files and resets the IDE to a clean state.

  • Manually Delete Build & Gradle Cache Directories
    Leftover build artifacts can often cause stuck builds. Let's clear these out:

    • In your Flutter project root, delete the build and .dart_tool folders.
    • Navigate to android/.gradle in your project and delete all its contents.
    • Clear the global Gradle cache too: on macOS/Linux it's at ~/.gradle/caches, on Windows it's C:\Users\<YourUsername>\.gradle\caches.
  • Verify Gradle Wrapper & Plugin Versions
    Double-check that your project's Gradle wrapper matches the version you're targeting. Open android/gradle/wrapper/gradle-wrapper.properties and confirm the distributionUrl points to the correct Gradle version (e.g., https\://services.gradle.org/distributions/gradle-7.5-all.zip). Then check android/build.gradle to ensure the Android plugin version is compatible:

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2' // Should match your Gradle wrapper's major version
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
    
  • Update Android SDK Components
    Open the Android SDK Manager (Tools > SDK Manager) and verify these components are up to date:

    • The Android SDK Build Tools (match the version specified in android/app/build.gradle under buildToolsVersion).
    • The SDK Platform for your project's targetSdkVersion (check android/app/build.gradle to confirm which one you need).
    • The Android Command-line Tools (under the SDK Tools tab, check "Show Package Details" and install the latest version).
  • Run a Clean, Fresh Build
    After clearing all caches, run these commands to trigger a completely fresh build:

    flutter clean
    flutter pub get
    flutter build apk --debug // Or your target build type (release, profile)
    
  • Check for Third-Party Dependency Conflicts
    If you're using external packages, they might have conflicting dependencies with your Android setup. Run flutter pub deps to view your full dependency tree and look for version clashes. If you find any, you can use the dependency_overrides section in your pubspec.yaml to force a compatible version for the conflicting package.

If none of these steps resolve your issue, sharing the full error message from Android Studio's "Build" tab (or the terminal output when running flutter build) will help pinpoint the exact problem—error logs almost always have clues we can use to fix this!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 09:29:52