I'm building a flutter app that uses protocal buffers and I would like to compile the .proto
file during the build process. How can I run a custom shell command before the dart compilation of a flutter build?
1- The first one is to use the debugShowCheckModeBanner property in your MaterialApp widget . And then do a hot reload. 2-The second possibility is to hide debug mode banner in Flutter Inspector if you use Android Studio or IntelliJ IDEA . 3- The third possibility is to use Dart DevTools .
Flutter doesn't have this capability yet, it's kind of better to have a pre-build script.
my-pre-build.sh
# my-pre-build.sh (run some commands)
Usage
./my-pre-build.sh && flutter build apk
You could also abstract the build using something like a Makefile, which makes things simpler in my opinion.
Makefile (in root of your project)
# Build for Android (runs build-proto first)
build-apk: build-proto
flutter test
flutter build apk
# Build for iOS (runs build-proto first)
build-ios: build-proto
flutter test
flutter build ios
# Proto generation (calls terminal proto commands)
build-proto:
proto-native-lib compile -f *.proto
Usage
make build-android
make build-ios
This is a useful way to bundle repetitive commands and reuse scripts between different build types.
I believe you can do this in Android Studio.
1. Go to Run > Edit Configurations
2. Add a new Shell Script configuration from (+) Add New Configuration > Shell Script
3. Setup your shell script execution. Make sure to click on Apply
after you're done. But don't close it yet.
4. Select Flutter > Run/main.dart > Before Launch > (+)Add > Run Another Configuration
5. Choose your Shell Script configuration
6. Click Apply
then click OK
. Your configured Shell Script will now run.
In case you'd like to consider something different, I accomplish exactly what you are requesting by using an external build tools. In my case I chose https://fastlane.tools/, which neatly integrates with Flutter, works for Android and iOS and it's open source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With