升级Flutter后出现:app:transformClassesWithDexBuilderForDebug错误求助
: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 least3.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.propertiesand 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
androiddirectory 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.gradleand enable MultiDex in thedefaultConfigblock: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
dependenciesblock: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
androiddirectory 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

