This Bash script is designed to rename APK files generated by Flutter.
Before: app-arm64-v8a-release.apk
After: MyAwesomeApp-armeabi-v8a-v1.0.0.apk
Note
Version number if extracted from pubspec.yaml file
Make sure your system has yq installed.
Do not install yq from sudo apt install yq, because it might download the different version of yq. See https://github.com/mikefarah/yq to install the correct yq.
The script requires two mandatory arguments and accepts an optional third:
AppName: The new name to replace the app part of the APK filenames./path/to/directory: The directory where the APK files are located.path/to/pubspec.yaml: Optional path to the YAML file containing the version information. Default topubspec.yaml. Example Command:
./rename_apk.sh MyApp build/app/outputs/apk/releaseor
./rename_apk.sh MyApp build/app/outputs/apk/release /path/to/custom_pubspec.yamlTips: You can use the script directly without downloading using curl. Example:
curl -s https://gist.githubusercontent.com/iqfareez/f57405016cc8bcc51cdcd2879c88807a/raw/5d9bbed7231a9e56bf24b88ab5286cee73dae173/rename_apk.sh | bash -s MyApp build/app/outputs/flutter-apk By default, Flutter output the generated apk or appbundle as app-<abi>-release.apk. The naming is boring, but can customize the filename using archivesBaseName property in app/build.gradle file. However, Flutter throws false positive error when building the app:
Gradle build failed to produce an .aab file. It's likely that this file was generated under [...], but the tool couldn't find it.
This can become headache especially in CI workflow. Thus, I make this script so that we can rename the apk files without depending on archivesBaseName property.