VS Code Flutter auto hot reload not working after updating - android

After I updated my Dart extension in VS Code, it doesn't automatically hot-reload my Flutter codes even though I've turned on autosave. Does anyone have an idea about how to solve it?

If you using VS Code, Go to the Settings > Extensions > Dart & Flutter
Then select always in Flutter Hot Reload On Save
Congrats 🥳 Your problem is solved.
PFA screenshot here

Run the flutter doctor command and make sure that flutter is installed properly on your machine.
Which channel are you running on? Make sure that you run on the stable channel, as long as it does not give you any compile time issues.
If the flutter doctor works, then make sure that, if you are running on iOS (Physical Device), that you have bonjour service enabled. This is required in order to make debugging work on physical devices (for iOS 14+). Please also make sure that you add -v command to the end of your deploy function, to increase the log verbosity.
Otherwise you can just deploy to the simulator.
If you are running on Android, there should not be any issues, unless there is a problem with the logcat. In this case you can try to go to android Studio and reboot the ADB (Android Debug Bridge), in which case the machine will try to reattach a debuggable process to your device. If it's still not working, then try another device. If that's not working, then add the -v command, I mentioned earlier, about log verbosity.
Post an update on your issue, once you have tried all of these suggestions.
[EDIT]
Please make sure that hot reload is enabled on the vscode settings.
Go to Settings > Search > Hot Reload, and make sure it's enabled for both Auto Save & Restart.
Please take a look at this image below:
[EDIT ONCE AGAIN]
If you look at the flutter documentation (https://flutter.dev/docs/development/tools/hot-reload) it says, that to run a flutter hot reload, you have to follow these steps:
Run the app from a supported Flutter editor or a terminal window.
Either a physical or virtual device can be the target. Only Flutter
apps in debug mode can be hot reloaded. Modify one of the Dart files
in your project. Most types of code changes can be hot reloaded; for a
list of changes that require a hot restart, see Special cases. If
you’re working in an IDE/editor that supports Flutter’s IDE tools,
select Save All (cmd-s/ctrl-s), or click the hot reload button on the
toolbar.
Make sure that you follow all the steps in the documentation, then let's talk on this post again (https://flutter.dev/docs/development/tools/hot-reload)

Asked and answered over here: Flutter doesn't hot reload on autosave in VSCode. In short, it is working as designed.

The "hot reload on save" feature was intended to run when the user specifically pressed save so they had some control over when it occurred. Some users experienced issues where autosave would cause it to fire when they didn't want it to, so this "bug" was recently fixed.
It turns out that for many users, hot-reload-on-autosave worked fine, so the next version of the Dart extension will include a setting to allow you to re-enable that.
"dart.flutterHotReloadOnSave": "always"

For VS Code Go to 'File' -> 'Auto Save' make sure you have "check" Auto Save.

If you’re running the app at the command line using
flutter run
command, enter r in the terminal window to hot reload.
Try to run by clicking Run button worked in my case.
Like this

Related

Can't see the code flowing while using chrome://inspect/#devices?

I am working on an app,which I have installed in my Smartphone, I wanted to check the flow of code while running the app.
using Android Studio I installed the app via USB Debugger, and open the app project files in
chrome://inspect/#devices
, while running , I have added multiple breakpoints in the code to see the flow, but the code haven't stopped at any breakpoint, yet there is no issue with the running of app, the app ran smoothly.
I am facing the same issue while using emulator as well.
Can someone help me to figure out, what I could do ?
EDIT -
I have followed #KannanSJD instructions as well, by "Attaching Debugger to Android" and selecting "Java Only" but not got any success. , As you can see in the below attachments
make sure you attach your debugger to your app process. Use the below icon on top left
if your app package and its process is not showing then make sure you are running in Debug mode and not in release mode using build variants.
Make sure your app is open and you see your process as in screenshot.
Also instead of detect automatically you cna use Java only if you have NDK also used in your project. This will fasten the process of attaching debugger.
Also make sure you find the following log in your debug console.
Please check if you have muted your breakpoints, refer following image. That should NOT be enabled.

React native Ctrl M or dev tool not showing in my emulator

He thanks in advance,
In react native am not able to right click or open dev mode in emulator.
adb shell input keyevent 82
Use this in your windows command line, It works for me.
If the above solutions did not help, here is what worked for me.
Use an emulator that has Play Store installed. When creating a virtual device in Android Studio, it will have the Play Store icon.
Download Expo from the play store. For some reason, the Expo app that vscode pushes to my emulator won't work properly for me.
Run expo start and open the Expo Developer Tools page on your browser (by typing 'd' if it does not open automatically), and copy the url at the bottom left. Will look like exp://127.0.0.1:19000 if you started with --localhost
On the emulator, run the expo app and on the top select Open from Clipboard and it will show the url you copied.
For me, this did a better job at starting the Building Javascript bundle, and once the app was loaded, I was able to use Ctrl M to mimic shaking the device and open the developer menu!
Other troubleshooting tips I learned while figuring this out:
Like the comments above state, don't be in production mode
Make sure to have paths set up correctly to be able to reach your Android sdk, nodejs, and your local project node_modules/bin if you are not doing global npm installs.
If you are having issues with remote debugging, make sure the Chrome debugger is not open. Close it if it is open, have your debugger listening on the correct port (for me 19001) and reload the project on the device.
I hope this helps someone.
FOR WINDOWS 10 YOU NEED TO ADD THIS SO THAT YOU CAN USE CRTL+M to open debug and reload
Add environment variables
Open a File Explorer, copy and paste the following into the address bar.
Control Panel\System and Security\System
Click on Advanced system settings on the left menu.
Click on Environmental Variables at the bottom.
Click on New to add a user variable (the top section).
You’ll be adding two:
Variable Value
ANDROID_HOME C:\Users\username\AppData\Local\Android\Sdk
JAVA_HOME C:\Program Files\Android\Android Studio\jre\jre
Then under System variables (the bottom section), click on the Path variable and click on Edit.
On the pop-up window, click on New to add another variable:
C:\Users\username\AppData\Local\Android\Sdk\platform-tools
C:\Program Files\nodejs\
Click OK, OK
Then try your emulator
see this link: https://medium.com/#lpault29/react-native-environment-for-windows-e25806df867c
Turning off production mode solved my problem.
There is post which says turn off production mode -> it took me time to find in which settings -> I was looking in emulator settings, it was in expo-cli. This post is it clarify it.
Production mode off
In the expo-cli http://localhost:19002/, there is Production Mode (left side bar) -> turn it off
Open AVD Emulator and your application, press ctrl+M
It should work.
*Make sure we installed all of these SDK files,I tried all of the above solutions but no one solved my problem but everything is working now after doing this, hope it will solve your problem also

Force Stop Running Application Before Build in Android Studio

I know there is an option to "force stop running application before launching activity" (which I do have enabled) but I'm after a way to have the same program exit as soon as I click the "play" button. I believe this is what use to happen before an upgrade but ever since the upgrade I've been unable to find a way to do it.
The reason I'm after this is because before (when the app closed when I pressed the button) it was really easy to tell when the new edit of my app was up and running on the device. Now that the old version keeps running I frequently make mistakes thinking the new version is already running before it is, or more commonly, not realising the new version is ready thinking the version I am looking at is the old one.
Is there a way to bring back the behaviour I seem to remember having before?
Thanks.
You can disable Instant Run via Settings -> Build, Execution, Deployment in Android Studio
Disable the Instant Run option from Settings as follows:
I think check thd delendencues and any error code written in any java as well as manifest file of application . I have done and my app is running.

How do you debug React Native?

How does one debug their React code with React Native while the app is running in app simulator?
Mac: Cmd+M
Windows and Linux: Ctrl+M
Use the appropriate hotkey above from within the Simulator. It'll popup Chrome and from there you can use the Developer Tools.
Edit:
This is now linked in the help docs.
Debugging React Native Apps
To debug the javascript code of your react app do the following:
Run your application in the iOS simulator.
Press Command + D and a webpage should open up at http://localhost:8081/debugger-ui. (Chrome only for now) or use the Shake Gesture
Enable Pause On Caught Exceptions for a better debugging experience.
Press Command + Option + I to open the Chrome Developer tools, or open it via View -> Developer -> Developer Tools.
You should now be able to debug as you normally would.
Optional
Install the React Developer Tools extension for Google Chrome. This will allow you to navigate the view hierarchy if you select the React tab when the developer tools are open.
Live Reload
To activate Live Reload do the following:
Run your application in the iOS simulator.
Press Control + Command + Z.
You will now see the Enable/Disable Live Reload, Reload and Enable/Disable Debugging options.
For an Android App, if you're using Genymotion you can toggle the menu by pressing CMD + m, but you may have to enable it in the menu by doing this.
Untick widget
Enable it by CMD + m click on debug in chrome
if you want to debug using android device on Windows just open a command prompt then type ( make sure your adb working properly)
adb shell input keyevent 82
it will prompt a screen like the image
then select
debug JS Remotely
it will automatically open a new window.then open inspect element or press F12 for console.
In addition to the other answers. You can debug react-native using the debugger statement
example:
debugger; //breaks execution
Your chrome dev tools must be open for this to work
cmd ⌘ + D oddly didn't work for me. Pressing ctrl + cmd ⌘ + Z in the iOS simulator did kick off the debugging browser window for me.
This is the screen that pops up:
More details here.
Try this program: https://github.com/jhen0409/react-native-debugger
Works on: windows, osx and linux.
It supports: react native and redux
You can also inspect the virtual component tree and modify styles that are reflected in the app.
Debugging react-native 0.40.0 on Debian 8 (Jessie) can be done by navigating to http://localhost:8081/debugger-ui in Chromium or Firebug while your app is running in the android simulator. To access the in-app developer menu, run the following command in another terminal window, as pointed out here:
adb shell input keyevent 82
I don't have enough reputation to comment on the previous answers which are great. :)
Here are some of the ways how I am debugging when developing react-native app.
Live reloading
react-native makes it super easy to see your changes with the ⌘ + R keys or even just enable live reload and watchman will "refresh" the simulator with the latest changes. If you get an error, you can get a clue from the line number from that red screen. A couple of undo will get you back to working state and start again.
console.log('yeah, seriously.')
I find myself prefer letting the program run and logging some informations than adding a debugger break point. (tough debugger is useful when trying to work with external packages/libraries and it comes with autocompletion, so you know what other methods you can utilise.)
Enable Chrome Debugging with debugger; break point in your program.
Well it depends on the type of errors you encountered and your preferences of how to debug. For most of the undefined is not an object (evaluating 'something.something'), method 1 and 2 will be good enough for me.
Whereas dealing with external libraries or packages written by other developers will require more effort to debug hence a good tool like Chrome Debugging
Sometimes it is coming from the react-native platform itself so googling for react-native issues will definitely helps.
hope this helps someone out there.
React Native 0.62 Released - The Official solution is Flipper 🚀
Flipper is Android & iOS Mobile debugging tools without using debug mode in react native.
Since RN 0.62 (See this link), Flipper is initialized with default project.
Flipper has a few of plugins for debugging. The plugins include Layout, Network, Shared preferences
The greatest benefit of Flipper is not also many plugins but you can see Android / iOS device console debugging easily too.
The Flipper alert you about crash or network rejection too.
Layout plugin includes accessibility mode and target mode.
You can also see raw network request / response in your Application.
Instead of Cmd+M, for Android Emulator Press F10 in Windows. The emulator starts to show all the react-native debug options.
For Android: Ctrl + M (emulator) or Shake the phone (In Device) to reveal menu.
For iOS: Cmd + D or Shake the Phone to reveal menu
Make sure you have chrome.
On the revealed menu select Debug JS Remotely Option.
Chrome will be opened automatically at localhost:8081/debugger-ui. You can also manually go to debugger with this link.
There reveal console and you can see logs being noted.
adb logcat *:S ReactNative:V ReactNativeJS:V
run this in terminal for android log.
If you are using Microsoft Visual Code , then install React Native Tools extension. Then you can add break points simply by clicking on the desired line number.
Follow these steps to setup and debug app :
Dont forget to enable Debug JS Remotely in emulator if you using it.
To me the best way to debug on React-Native is by using "Reactotron".
Install Reactotron then add these to your package.json:
"reactotron-apisauce": "^1.1.2",
"reactotron-react-native-under-37": "^1.1.2",
"reactotron-redux": "^1.1.2",
now, it just the matter of logging in your code.
e.g.: console.tron.log('debug')
Run your app in simulator - react-native run-ios
Press ctrl + d and click on Debug JS Remotely
webpage should open up at http://localhost:8081/debugger-ui , if not type the URL and go to this link in Chrome
Right click on the page and click Inspect and it should open the developer tools for chrome
Go to the sources in the top menu and find your js class file in the right hand side file explorer
You can put breakpoints to the view and debug the code in there as you can see in the image.
If you want to enable debugging by default:
import { NativeModules } from 'react-native';
if (__DEV__) {
NativeModules.DevSettings.setIsDebuggingRemotely(true)
}
To get this working on Android:
npm install --save react-native-devsettings-android
react-native link react-native-devsettings-android
Reference: Launch a React Native app with “Debug JS Remotely” enabled by default
First in your ios simulator, if you press [command + D] key then you can see this screen.
Then click Debug JS remotely button.
After you might see React Native Debugger page like this.
And then open your inspector[f12], and go to console tab debug it! :)
By default, my ios simulator wasn't picking up the keystrokes which is why cmd-D didn't work. I had to turn on the settings for the keyboard using simulator's menu:
Hardware > Keyboard > Connect Keyboard
Now cmd-D launches chrome debugging.
For android app .Press Ctrl+M select debug js remotely it will open a new window in chrome with url http://localhost:8081/debugger-ui. You can now debug the app in chrome browser
Having a space in the file path prevents the Cmd+D from working. I moved my project to a location without a space and I finally got the Chrome debugger to work. Seems like a bug.
You can use Safari to debug the iOS version of your app without having to enable "Debug JS Remotely", Just follow the following steps:
1. Enable Develop menu in Safari: Preferences → Advanced → Select "Show Develop menu in menu bar"
2. Select your app's JSContext: Develop → {Your Simulator} → Automatically Show Web Inspector for JS JSContext
3. Safari's Web Inspector should open which has a Console and a Debugger
Very simple just two commands
For IOS $ react-native log-ios
For Android $ react-native log-android
If you are using emulator use Ctrl+M & simulator Cmd+D
Click on the - Debug js remotely
Google Chrome go to console
Assuming you want to show this menu on Android emulator
Then, try ⌘+m to pop up this dev settings dialog on Android emulator on a Mac.
If it doesn't show then go to AVD > (click the pen to edit your emulator configuration) > advanced settings > check the enable keyboard input box.
And then retry ⌘+m.
If it doesn't show still then go to the running emulator settings and on the Send keyboard shortcuts to combobox/dropdown then select the Emulator controls (default) option.
And then retry ⌘+m.
I hope this helps, it worked for me.
If you're using Redux, I highly recommend React Native Debugger. It includes Chrome devtools, but also has Redux devtools and React devtools.
Redux Devtools: This allows you to view your actions, and step back and forth through them. It also allows you to view your redux store and has a feature to automatically diff the previous state with the updated state for each action, so you can see that as you step back and forth through a series of actions.
React Devtools: This allows you to inspect a certain component, namely all of it's props as well as it's component state. If you have a piece of the component state which is a boolean, it lets you click it to toggle it and see how your app reacts when it changes. Great feature.
Chrome Devtools Allows you to see all your console outputs, use breakpoints, pause on debugger; etc. Standard debugging features. If you right click the area where your actions are listed in Redux Devtools and select 'Allow Network Inspect', you can then inspect your API calls in the network tab of Chrome Devtools which is sweet.
In conclusion having these all in one place is fantastic! If you don't need one of them you can toggle it on/off. Get React Native Debugger and enjoy life.
In React-Native debugging is much easier.
To debug in IOS use
cmd + d
ctrl + cmd + z ( For simulator )
To debug in android
Shake device with touch ( Make sure your developer option is enable )
This is the alternate way to use react native debugger application.
you can download application using below link it's very good application for managing redux store along with the source code.
react-native-debugger
as well now a days you may directly use below link for help you out.
chrome-developer-tools
Step 1:
Place debugger where ever you want to stop script, like:
async saveItem(item, selectedValue) {
debugger
try {
await AsyncStorage.setItem(item, selectedValue);
}
catch (error) {
console.error('AsyncStorage error: ' + error.message);
}
}
This will pause the debugger when ever control comes to this block of code.
Step 2:
Press Cmd+D on ios emulator and Cmd+M on Android simulator.
If you are having real device, shake the device to open dev menu, if you don't want to shake device follow this blog
Step 3:
Select Enable Remote JS Debugging, this will open Chrome
Step 4:
Select Developer Tools.
Step 5:
Your debugger is paused in Sources tab wherever you have written debugger within your code . Go to console and type any parameters you want to debug (that are present in the code block) like:
To move to next debugger point again move to Sources -> click on Resume script execution button (Right corner blue button)
Place the debugger, wherever you wanna pause the script.
Enjoy debugging!!
There is also a very good debuger name Reactotron.
https://github.com/infinitered/reactotron
You don't have to be in debug mode to see some data value and there is a lot of option.
go have a look that is really usefull. ;)

Possible reasons/fixes for build error for Android Emulator

STEPS-TAKEN: Not sure what the source of the problem is, but the quick description of the bug is that:
I install all required software, SDKs, configs,
Then create two new projects each using the tabbed-window template, each of which support deployment to Android.
Then I run one project via Titanium Studio's Run option, let the Android Emulator load, and confirm it's the app is installed an working.
Then I closed the emulator, and then run the other project the same way as the last, though when the app is shown on the screen it has the name of the first app, not the app run.
FIXES-TRIED: I've attempt executing "Project >> Clean" for all projects before the second run, and still get the same "bug".
SETUP: To my knowledge all of my configs are correct, and clearly the build "works" though it is very possible there is something wrong with my installation build chain to get to the point I'm running the app in Titanium Studio via the Android Emulator.
ERRORS: I've reviewed the console output for FastDev, AppInstall, Android-Emulator, etc and have seen no error messages that jump out; meaning I have seen no error messages, except for build.py error after the first script runs saying it didn't find the script running on a port when it attempt to kill it; given the request is to kill itself, and it's not found, I just assume this is a confusing way of saying the script did what it was suppose to do.
Current build: is on Windows-XP-SP3 using TiStudio 2.0.1 build, JavaSDK 1.6, r18-Android, and Android-2.2
Recent emulators have persistent state, so your second launch probably gets back the system you were running before.
You should not have to resort to this on a regular basis unless something is broken in the workflow, but deleting the AVD and making a new one should get you a clean slate.
I believe there is also a startup flag to the emulator which tells it not to use the checkpoint from a previous run, but start from scratch - you could try to change your configuration to use that flag.
A downside to either deleting or forgoing checkpoints is that the emulator will take longer to start up.
Really though, you are supposed to be able to re-install or launch a given application, or install a completely different one, all within the same running of an emulator. You aren't supposed to need a new emulator, any more than you need to go buy a new device (or perform a factory reset on it). So something is not right in the setup, and the best solution for long term productivity is to identify and fix that. Short term of course, you might need to wipe the slate clean if that helps you meet today's deadline.

Categories

Resources