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

升级Flutter后出现:app:transformClassesWithDexBuilderForDebug错误求助

Fixing :app:transformClassesWithDexBuilderForDebug Error After Flutter Upgrade

Let's work through this issue step by step—this Dex Builder error is a common hiccup when jumping from older Flutter versions like v1.9.1 to v1.12.13+hotfix.5, and it almost always ties to mismatched Android build configurations. Here's how to resolve it:

1. Sync Android Gradle Configurations with Flutter 1.12+ Requirements

Flutter 1.12+ updated the minimum required Android Gradle plugin and Gradle wrapper versions. Head to your layers example project's android folder:

  • Open the project-level build.gradle (not the app-level one) and make sure the Android Gradle plugin version is at least 3.5.0:
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
    
  • Open gradle/wrapper/gradle-wrapper.properties and verify the Gradle distribution URL matches the plugin version. For plugin 3.5.0, use:
    distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
    

2. Clear All Build Caches

Stale cache files often cause post-upgrade build issues. Run these commands in order:

  • First, clean Flutter's build cache:
    flutter clean
    
  • Then navigate to the android directory and clean Gradle's cache:
    gradlew clean  # For Windows
    # ./gradlew clean  # For Mac/Linux
    

3. Enable MultiDex (If Needed)

The Dex Builder error can occur if your app exceeds the 64k method limit, which is more likely after upgrading dependencies. To fix this:

  • Open the app-level build.gradle and enable MultiDex in the defaultConfig block:
    defaultConfig {
        applicationId "io.flutter.examples.layers"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true  # Add this line
    }
    
  • Add the MultiDex dependency to the dependencies block:
    dependencies {
        implementation 'com.android.support:multidex:1.0.3'
    }
    

4. Get Detailed Error Logs (Instead of --stacktrace)

Note that flutter run doesn't support the --stacktrace option—this is a Gradle-only flag. To get the full details of what's causing the Dex error:

  • Either run Flutter in verbose mode:
    flutter run -v
    
  • Or navigate to the android directory and run the Gradle build directly with stacktrace:
    gradlew assembleDebug --stacktrace
    

This will show you exactly which class or dependency is triggering the failure, which is useful if the above steps don't resolve the issue.

5. Re-fetch Dependencies

Sometimes upgrading Flutter leaves outdated dependency references. Run:

flutter pub get

Quick Note on Your flutter doctor Output

While your setup can run Flutter via the command line, installing the Flutter and Dart plugins for IntelliJ will make debugging and configuration easier—though this isn't the root cause of your current build error.

内容的提问来源于stack exchange,提问作者Nguyễn Thanh

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 09:04:12