App running on debug mode only for Flutter - android-studio

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.

Related

Flutter "Entrypoint isn't within the current project." error on Android Studio

Flutter app runs on VS Code with Start Debugging & Run Without Debugging and also with terminal command "flutter run" .
However it runs on Android Stuido only with terminal command "flutter run".
When I try to run it on Android Studio, with the play button which triggers the build, I get this error :
"Entrypoint isn't within the current project."
Invalidate Caches and Restart, flutter clean, quitting and restarting Android Studio are some options I tired with no success at all.
Have any of you faced the same issue?
What can be the problem? And please the solution...
Thanks in advance,
Oz
Here's the image of Run Config :
Click on File-> Project Structure -> Module then add root folder of your project then it will detect its a flutter app and then build
It works for me, hope it will work for everyone.
Goto File -> Project Structure -> Module
Or
in edit configuration, just name it "main" and locate the location of 'main.dart' file in the Dart entrypoint text field.
Please take a look at the below screenshot.
Run/Debug Configuration screenshot

I try to make android studio (emulator) work with vs-code but have an error "avdmanager is missing from the Android SDK"

This is my PATH
export ANDROID_SDK_ROOT=/mnt/sda1/DevTools/sdk/
export ANDROID_HOME=$ANDROID_SDK_ROOT
export PATH=${PATH}:/mnt/sda1/DevTools/sdk/platform-tools
I try many cases, but still this error!
Try :
flutter doctor --android-licenses
if something wrong, try to locate android sdk path.
flutter config --android-sdk {path}
Mine :
flutter config --android-sdk C:\Android\Sdk
This worked for me. If you have sdkmanager, avdmanager and emulator, and you have them in your PATH environmental variable, then
Download a system image:
sdkmanager "system-images;android-30;google_apis_playstore;x86_64"
(you can find available packages with sdkmanager --list --verbose)
Create a new virtual device with
avdmanager create avd --name MyAndroidDevice --package "system-images;android-30;google_apis_playstore;x86_64"
Start the emulator
emulator -avd MyAndroidDevice
Now restart VSCode and open your Flutter project. The new device should be at the bottom right corner or you should be able to choose it by clicking on "No device".
For me, I had to restart my VS Code for the installation of Android SDK be reflected upon it.
I know this is an old question but setting my $PATH variable in ~/.bashrc (I'm on Ubuntu 20.04) did not work for me.
I needed to setup Android Emulator for VScode, because I wanted to run my flutter app, which seems to be the same issue as OP had.
Instead of setting the $PATH directly you can actually use Flutter in the terminal to do it.
If you run "flutter config" in the terminal you get something like:
Configure Flutter settings.
To remove a setting, configure it to an empty string.
The Flutter tool anonymously reports feature usage statistics and basic crash reports to help
improve Flutter tools over time. See Google's privacy policy:
https://www.google.com/intl/en/policies/privacy/
....
Run "flutter help" to see global options.
Settings:
android-sdk: <my_path_to_android_tools>
Analytics reporting is currently enabled.
You can then see the $PATH that is currently set with flutter under:
Settings:
android-sdk: <my_path_to_android_tools>
Mine was incorrect so I changed it to the current one with the command:
flutter config --android-sdk <my_path_to_android_tools>
Afterwards I restarted VScode and when it was finished loading I could now press the "device" button in the right hand corner and then select emulator that I had already created. I used one of the above answers to install the emulator itself.
It took a while to launch the emulator the first time due to installing some dependencies but it did work!
I tried this and works:
from terminal run flutter config --enable-android. You will get Setting "enable-android" value to "true".
after that open android studio, set up virtual devices first if you haven't. Open Android Studio -> Configure -> AVD Manager -> Create Your Virtual Device
Go back to your VS Code, open command Palette (Ctrl+P or cmd+P, then type >), or from View -> Command palette... -> Flutter: Select Device -> choose your android device
I faced the same issue and solved it running flutter doctor from the terminal, in VS Code. In my case, I had the android sdk located in a custom location (D drive), the reason why it wasn't found automatically. The "doctor" told me to run flutter config --android-sdk <my-sdk-custom-location>. Running it and restarting the IDE made the trick. Hopefully this helps someone facing the same problem.

Flutter How to make release version in Android Studio?

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.

I cannot stop the debugger

I'm trying to stop debbuger from running and I cannot figure out how. I've read everything here and still nothing. I made a weather app in flutter and I am ready to upload it to google play but I get the error that tells me I need to stop debbuging. Anyone know how to? Notice the debug banner on top right
You need to build a release version, using flutter build apk --release.
On your MaterialApp set debugShowCheckedModeBanner to false.
MaterialApp(
debugShowCheckedModeBanner: false,
)
The debug banner will also automatically be removed on release build.
If you are using emulator or real device and you want to check it on release mode
then =>
flutter run release --apk
run this command on terminal Android Studio / Vs Code

This version of android studio is incompatible with the gradle version used.Try disabling the instant run

I am able to build the app properly, but when I run it I get this error:
This version of android studio is incompatible with the gradle version used.Try disabling the instant run
You can use normal build run rather than instant run.
Check first
Go to Settings/Preferences > Build, Execution, Deployment option > Instant Run and uncheck all the three boxes.
Upgrading Gradle services URL:
Project > Gradle > Wrapper > gradle-wrapper.properties
Change URL from
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-all.zip
(Find latest distributionUrl gradle plugin version Here: http://services.gradle.org/distributions
**Make sure to use gradle-x.xx-all.zip
)
Delete your build folder
When you run project, build folder will be created automatically
Go to BUILD option in menu > Clean the project, Build the project
It should work without instant run.
I had easy steps & correct way also
1 - In Settings -> Build, Execution, Deployment option -> Instant Run
2 - Clear Enable instant run to hot swap code
3 - Clean project
p/s : It should totally work.
The Gradle Plugin used is typically the same as the version of Android studio you are using.
Check the Android Studio version
Help → About
and the version will read
Android Studio Version X.Y.Z
Then, go to
Project → Gradle Scripts → build.gradle(Project)
and under dependencies change the classpath to
classpath 'com.android.tools.build:gradle:X.Y.Z'
and rebuild/sync the project.
You can disable instant run by follow these steps in Android Studio:
File → Settings → Preferences dialog → Build → Execution → Deployment
→ Instant Run → Update Project
This feature introduced in Android Studio 2. however, when you disable it, next time when you try to push new app to your emulator is running much slower.
In my case I just update Android Studio to the latest build from canary channel and it's works without disable this feature.
Hope it's help
As commented by sjd: Just cleaning the project and build again might help if you, just like me, have used the automatic update applied by android studio.
I just did a Build > Clean project and then reRun app!
I wanted to run the app in debug mode and got the same message, so I tried:
File > Invalidate caches and restart...
Clean project
Build project
Nothing worked...
Then, I just clicked on the green arrow to run the project without debugging...
Worked!
So then I just added a debugging session with the option left of the stop button in Android Studio.
I did fix by this way.
Update your classpath to classpath 'com.android.tools.build:gradle:2.0.0' in your top level build.gradle file.
Done
I just Deleted the Build Folder and Clean project.It worked for me...!!!
In Android Studio 2.3.3
File -> Settings -> Build, Execution, Deployment -> Instant Run -> Unable Instant Run to hot swap code (Uncheck it)
Now, you have disable Instant Run...
It will solve Instant Run issue.

Resources