I'm encountering a build failure while running the flutter build apk command as part of my Bitbucket pipeline. The build process is failing due to issues with the Gradle shrinker, resulting in the following error message:
Build Failed in 12m 32s
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show individual deprecation warnings and determine if they come from your own scripts or plugins. See https://docs.gradle.org/8.0/userguide/command_line_interface.html#sec:command_line_warnings 882 actionable tasks: 881 executed, 1 up-to-date Some file system contents retained in the virtual file system are on file systems that Gradle doesn't support watching. The relevant state was discarded to ensure changes to these locations are properly detected. You can override this by explicitly enabling file system watching.
Running Gradle task 'assembleRelease'... (completed in 753.0s)
Flutter Fix
[!] The shrinker may have failed to optimize the Java bytecode. To disable the shrinker, pass the `--no-shrink` flag to this command. To learn more, see: https://developer.android.com/studio/build/shrink-code
Here are the last few lines of the log:
"flutter apk" took 755,487ms. Gradle task assembleRelease failed with exit code 1. #0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3) #1 AndroidGradleBuilder.buildGradleApp (package:flutter_tools/src/android/gradle.dart:544:7) #2 AndroidGradleBuilder.buildApk (package:flutter_tools/src/android/gradle.dart:224:5) #3 BuildApkCommand.runCommand (package:flutter_tools/src/commands/build_apk.dart:141:5) #4 FlutterCommand.run. (package:flutter_tools/src/runner/flutter_command.dart:1408:27) #5 AppContext.run. (package:flutter_tools/src/base/context.dart:153:19) #6 CommandRunner.runCommand (package:args/command_runner.dart:212:13) #7 FlutterCommandRunner.runCommand. (package:flutter_tools/src/runner/flutter_command_runner.dart:420:9)
Build Script
- export PATH="$PATH:/sdks/flutter/bin"
- flutter clean
- GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa" flutter pub get
- flutter build apk --verbose || { echo "Build failed"; exit 1; }
Solution This issue refers into proguard-rules if used inside the app in my case update this file and its work fine
You find missing's scripts inside mappings directories
A few things that helped me resolve this without completely disabling code shrinking:
First, check if you're running out of memory. Bitbucket Pipelines have limited resources, and the shrinker (R8/ProGuard) can be memory-intensive. Try adding this to your android/gradle.properties:
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512mSecond, look at your app's android/app/build.gradle and make sure you have proper ProGuard rules. Sometimes the shrinker chokes on specific libraries. You can enable more detailed logging to see exactly where it fails by adding:
android { buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' // Add this for more details shrinkResources true } } }
Third, regarding Gradle versions - yes, this can definitely help. I had success dropping from Gradle 8.0 to 7.5 in my project. Check your android/gradle/wrapper/gradle-wrapper.properties and try 7.5 if you're on 8.x.
Also, here's a pro tip: instead of running flutter clean every time (which wipes everything), try flutter pub cache repair occasionally. And consider adding --no-tree-shake-icons to your build command if you're using a lot of custom fonts.
Honestly, sometimes these CI builds can be more temperamental than getting Super Bear Adventure 2 to run smoothly on an older device! 😅 Although you can get it easily and have fun.
One last thing - try running the build with the shrinker disabled just once (--no-shrink) to confirm everything else builds correctly, then gradually enable optimizations. This helps isolate whether it's truly the shrinker or something else in your build config.
Hope this helps you get unstuck! Let me know what specific error messages you see when you enable verbose logging.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm facing an issue where the Flutter apk always failed using Bitbucket pipeline, and it's getting frustrating. Despite trying clean builds and checking for deprecations, the Gradle shrinker keeps causing build failures. Honestly, even something like Null's Brawl APK builds more reliably than this. Is there any known fix or Gradle version tweak that can resolve the shrinker issue without fully disabling it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The Gradle shrinker error in Bitbucket pipelines is usually due to version mismatch or limited memory. Try using a stable Flutter/Gradle combo and increase JVM memory
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mohammad!
I'm not familiar with flutter, so I can't answer any questions related to that. However, I can give you some context on the environment that Pipelines builds run so you can debug this.
If you run Pipelines builds on Atlassian's infrastructure or with a self-hosted Linux Docker runner, these builds run in Docker containers based on the Docker image you have specified in your bitbucket-pipelines.yml file.
If you have Docker installed on your computer, you can debug a Pipelines build locally with Docker following this guide:
If you follow the steps of the guide, you'll have a clone of the repo at the same commit as the failed build and also use the same Docker image.
You can then debug the issue locally without consuming Pipelines minutes and run additional commands to debug it.
You could also try different Docker images if the one you are using now does not have the version of the tools you need. We support public and private Docker images including those hosted on Docker Hub, AWS, GCP, Azure and self-hosted registries accessible on the internet:
If you run Pipelines builds with a self-hosted Linux Shell, MacOS, or Windows runner, these builds run directly on the host machine using Bash (Linux Shell and MacOS runners) and PowerShell (Windows runners). You can debug these builds outside the runner using Bash or PowerShell respectively.
Please feel free to reach out if you have any questions!
Kind regards,
Theodora
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are very welcome! Thank you also for posting the solution!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.