By default Android Studio use debug mode when building Flutter application. You can build the release version with the command line, see How to optimize the Flutter App size?
flutter build apk --release
Now: how to configure Android Studio to do the same, when I run the application (Shift+F10)? I can't find this setting...
You have to edit the run configuration:
Open the run configuration:
Add the --release flag:
Note that using the --release flag is not supported when you build with the Android Emulator.
In Android Studio , click on :
> Run
> Flutter Run 'main.dart' in Release Mode
flutter build appbundle --release --build-name=1.1.1 --build-number=3
Or you can run that in your Terminal, Remember to change build name and build number to corresponding values of your release app versioning.
as the green play button in toolbar runs the debug mode, i switched it to release mode via:
Right click Play Icon in toolbar -> Customize Toolbar
click "+", chose Add Action
chose "Plugins/Flutter/Run in Flutter release mode"
Delete the old Play button by selecting it and click "-"
The best way to make your apk for release mode is that open the project -> click on the android folder then make your apk as same as generated application build in android using your .jks key and alias password and name. this is the correct way for making apk in flutter.
Related
now I'm making an app using flutter and trying to upload the app as internal test on Google play store. I saw people asking how to do it, but could not figure it out...
On the official document, it says "Build > Build > Generate Signed Bundle/APK" and I can generate APK, but I don't see the "Generate Signed Bundle/APK".
When I select "Build APK" in the picture above, it gives me the message like
You are building a fat APK that includes binaries for android-arm,
android-arm64, android-x64. If you are deploying the app to the Play
Store, it's recommended to use app bundles or split the APK to reduce
the APK size.
To generate an app bundle, run:
flutter build appbundle --target-platform android-arm,android-arm64,android-x64
Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per ABI, run:
flutter build apk --target-platform android-arm,android-arm64,android-x64 --split-per-abi
Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Running Gradle task 'assembleRelease'...
27.9s ✓ Built build/app/outputs/apk/release/app-release.apk (19.2MB). Process finished with exit code 0
Also, I saw this chat (How to build signed apk from Android Studio for Flutter), but I cannot see "open android module in android studio"
Even when I opened the android project with different window, I cannot see the option as well..
it will be really helpful if someone can teach me how to generate the APK from my current situation...
Thank you so much..
The reason why Open Android module in Android Studio is missing under Tools > Flutter is likely because you're using an older version of Flutter DevTools on Android Studio. You can run flutter pub global activate devtools on the Terminal to update the DevTools installed on the machine as mentioned on this guide.
to build apk use this line in terminal
flutter build apk --release --no-sound-null-safety
I am completely new to flutter. I am trying to build https://github.com/flutter/udacity-course/tree/master/course/02_category_widget/task_02_category_widget but the Play Button won't enable.
I tried creating an APK of the project from the command line:
flutter build apk
and
flutter install
It creates an APK and runs on my Android device. I also tried creating a new Flutter Project and the Play button is working well on that. What am I missing in this project?
Check by running flutter doctor if you have everything installed
Check that Android Studio knows where your Flutter SDK is located. File->Settings->Languages and Frameworks->Flutter
I'm building a flutter app on a mac for the first time. Android studio doesn't provide me any way to build or run the app. The green triangle run button is greyed out, and it doesn't have a spot for me to select my emulator.
If I open an emulator and run the app from the command line it builds and runs just fine. The only issue is that android studio doesn't give me the option to run it at all.
Here's what my android studio looks like
And here's flutter doctor
I'd prefer to not switch environments and to continue being able to develop with android studio, instead of switching to xcode or VScode.
Thanks for any and all help!
The green triangle run button is greyed out for me too in Android Studio but the project can be run from command line using "flutter run".
To enable the run button in Android Studio, go to Settings->Languages & Frameworks->Dart:
Enable Dart support for the project (checkbox)
Set the Dart SDK path (on my machine it was "C:\flutter\bin\cache\dart-sdk")
Select the modules to enable Dart support
Screenshot of Android Studio Dart settings
Open pubspec.yaml in your IDE and click on packages get option
This should fix your problem.
I am not sure what is wrong with my Android Studio IDE, but whenever I run the app inside flutter it always runs on debug mode. Please see the label on the right side of the corner.
Logs:
Launching lib\main.dart on POCO F1 in debug mode...
Initializing gradle... Resolving dependencies... Running Gradle task
'assembleDebug'... Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk... Syncing files to device
POCO F1...
Have you tried running your code in "release" mode?
Within a terminal you can do that via flutter run --release.
In Android Studio you could double tap shift to bring up the search everywhere command window. If you simply type release you should be able to find the Flutter Run main.dart in Release Mode command.
Also you can find this in the menu under "Run" just like so:
Running commands:
App by default runs on debug mode, it is bit janky but needed to provide features like hot reload and hot restart. However, if you want to run the app in other modes, try these commands:
Release mode:
flutter run --release
Profile mode:
flutter run --profile
Adding flags in the IDE:
You can also add these flags in IDE, click on main.dart in the toolbar:
Add --release flag in the Additional run flags option
From Run→Edit Configurations, you can create two configurations (copy and paste the first, then rename) add additional’s arguments as --debug for debug an --release for release and chose one of those to start your app in Debug mode or Release mode (Let gradle to build for you :) ).
If you build your apps in vsCode.
Then, open your terminal(CTRL + `) and type a command.
flutter run --release
To remove the flutter debug banner, there are several possibilities :
1- The first one is to use the debugShowCheckModeBanner property in your MaterialApp widget .
Code :
MaterialApp(
debugShowCheckedModeBanner: false,
)
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 .
But if you want to switch to release mode ,
Use this command for running your app flutter run --release
or
In Android Studio , click on :
> Run
> Flutter Run 'main.dart' in Release Mode
I always prefer to learn shortcuts
You can use the following Shortcuts to open the configuration of the run and write --release
ALTSHIFTF10 then Press 0 and Press ALTa
Finally, you are there where you just have to write --release and Press ENTER
Thats it!
I only change package name at /android/app/src/main/kotlin/MainActivity.kt as the same with applicationID at /android/app/build.gradle,
and now it's running...
If you want to just get rid of the debug tag from the rightmost corner of the app,
u can use the
this => debugShowCheckedModeBanner: false
into your main.dart file in the material app widget.
I installed Flutter and Android Studio following this link here:
https://flutter.dev/docs/get-started/editor
I've been coding in flutter for two months now and can run my app in simulator or on a connected device no problem.
But when I try to actually build an apk via "Build" --> "Build Bundle(s) / APK", this option is greyed out.
Android Studio: 3.3.2
You can't build apk using Build option in Android Studio if you are running your Flutter project.
There are 2 solutions to build it.
In terminal, write flutter build apk (this will build apk for release version not the debug version)
Open your module in Android Studio and you can use Build option of the Android studio to build the debug apk.
For option 2, you can go to build.gradle file and you should see an option in Android Studio asking you to open the module separately (see the screenshot) Tap on this option and you can then build your apk in both debug and release mode.
I realize this might have already been answered, but I have another solution to this issue. I was having the same problem after modifying my pubspec.yaml file, so after trying to build within terminal nothing would happen. Apparently, you have to open the .yaml file within Android Studio from your project directory in order to for AS to realize that there's been a change to the file. After I opened the file from the project folder, the option for Build > flutter > Build Bundle(s) /APK > Build App Bundle finally reappeared again. Just sharing my experience and hope it can help someone else who may come across this rather strange issue.
Reopen the project from your projects directory, not from recent projects option. This solved for me
Please follow these steps:-
Go To Project Structure>Project>NOSDK
Change NOSDK to the latest
ANDROID API PLATFORM
Then go to MODULE and DO THE SAME