I'm getting a build error when trying to run my Flutter project. The build fails with a Gradle exception related to resource and code shrinking. I haven't changed any minifyEnabled or shrinkResources settings. :
FAILURE: Build failed with an exception.
- What went wrong: A problem occurred configuring root project 'android'.
Removing unused resources requires unused code shrinking to be turned on. See http://d.android.com/r/tools/shrink-resources.html for more information.
- Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
What I Tried:
I ran flutter clean from the terminal, followed by flutter pub get, in an attempt to clear any corrupted build cache.
I then tried to explicitly enable code shrinking by adding minifyEnabled true inside the release block of my app/build.gradle file.
I also tried the opposite approach, disabling resource shrinking by setting shrinkResources false in the same build.gradle file.
What I Was Expecting:
I was expecting flutter clean to resolve any cache-related issues and allow the build to complete successfully, but the build error persisted.
When I added minifyEnabled true, I was expecting the build to succeed because the error message specifically mentioned this was required. The build did succeed, but I'm now facing a new issue (e.g., app crashes, or a specific feature doesn't work), which leads me to believe this might not be the correct solution, or it requires additional configuration.
When I disabled shrinkResources, I was expecting the build to complete successfully without any code or resource optimization, but the same error message appeared, which was unexpected.
1 Answer 1
the error happens because shrinkResources is enabled without minifyEnabled, which Android does not allow. To fix this, open android/app/build.gradle and check both are set consistently in your release block, either disable both (minifyEnabled false and shrinkResources false) if you just want your build to succeed, or enable both (minifyEnabled true and shrinkResources true) if you want shrinking, in which case you must also include proper proguard-rules.pro to prevent Flutter or plugin code from being stripped out. if a plugin is forcing shrinkResources, you can disable it globally in gradle.properties with android.enableResourceShrinker=false. Which should ensure the build system sees a valid configuration and thus removing the error.
Comments
Explore related questions
See similar questions with these tags.