This minimal example illustrates a release build error in Flutter 3.35.0+ when using Android dynamic install-time modules. The error originates from a compileOnly dependency conflict. To successfully build, using Flutter SDK 3.32.6 or lower can serve as a temporary workaround.
For Flutter applications integrated with Android dynamic install-time modules, release builds (using flutter build appbundle or flutter build apk --release) with Flutter SDK versions 3.35.0 and above may fail. The error is typically related to compileOnly dependency conflicts during the build process, especially when shared library versions clash between the main module and dynamic feature modules.
Note: This error only occurs when building or running in release mode. Debug mode will not exhibit this error.
This project is pre-configured with a dynamic feature module. Follow these steps to reproduce the error:
-
Check Flutter SDK version: Ensure you are using Flutter SDK version 3.35.0 or newer. You can check the version with the command:
flutter --version
If you are on an older version, update Flutter:
flutter upgrade. -
Prepare the environment: Run the following commands in the project's root directory to ensure dependencies are fetched and the build cache is clean:
flutter clean flutter pub get
-
Attempt to Build or Run Release (Will fail) using Android Studio / IntelliJ IDEA:
- Open the
androiddirectory of the project in Android Studio or IntelliJ IDEA (UseFile->Openand select theandroidfolder within your Flutter project). - Wait for Gradle to synchronize the project.
- In the
Build Variantswindow (usually on the left or bottom side of the IDE), selectreleasefor all relevant modules (yourappmodule and your dynamic feature module). - Perform one of the following actions to trigger a release build:
- Select
Build->Make Project(orRebuild Project). - Select
Build->Build Bundle(s) / APK(s)->Build Bundle(s)(orBuild APK(s)). - Press the Run/Debug button (green arrow icon) on the toolbar after selecting a device or emulator, ensuring the run configuration is set to release mode.
- Select
- The build or run process will stop with error messages in the IDE's
BuildorRunwindow, typically indicating dependency conflicts orcompileOnly-related issues, which are characteristic of dynamic feature modules.
- Open the
To confirm that downgrading the Flutter SDK resolves the issue, follow these steps:
-
Downgrade Flutter SDK: Switch the Flutter SDK to version 3.32.6:
flutter downgrade 3.32.6
Note: After downgrading Flutter, you may need to update the Dart SDK version in the
pubspec.yamlfile (underenvironment: sdk:) to ensure compatibility with the downgraded Flutter version. For example, Flutter 3.32.6 might require a different Dart SDK version than Flutter 3.35.0+. -
Prepare the environment again: After downgrading, clean and fetch dependencies again:
flutter clean flutter pub get
-
Attempt to Build or Run Release again (Will succeed) using Android Studio / IntelliJ IDEA:
- Ensure you still have the
androiddirectory of the project open in Android Studio / IntelliJ IDEA. - In the
Build Variantswindow, ensure thatreleaseis still selected for the modules. - Perform one of the following actions to trigger a release build:
- Select
Build->Make Project(orRebuild Project). - Select
Build->Build Bundle(s) / APK(s)->Build Bundle(s)(orBuild APK(s)). - Press the Run/Debug button (green arrow icon) on the toolbar, ensuring the run configuration is set to release mode.
- Select
- This time, the build or run process should succeed, confirming that the error only occurs with Flutter SDK versions 3.35.0 and above when dynamic feature modules are present.
- Ensure you still have the