1434d8818SAman Mittal--- 2434d8818SAman Mittaltitle: Debugging runtime issues 3434d8818SAman Mittaldescription: Learn about different techniques available to debug your Expo project. 4434d8818SAman Mittalsidebar_title: Runtime issues 5434d8818SAman Mittal--- 6434d8818SAman Mittal 7434d8818SAman Mittalimport { BoxLink } from '~/ui/components/BoxLink'; 8434d8818SAman Mittalimport { Step } from '~/ui/components/Step'; 9434d8818SAman Mittalimport { Terminal } from '~/ui/components/Snippet'; 10434d8818SAman Mittalimport ImageSpotlight from '~/components/plugins/ImageSpotlight'; 11*fa939da8SAman Mittalimport { BookOpen02Icon } from '@expo/styleguide-icons'; 12434d8818SAman Mittal 13434d8818SAman MittalWhether you're developing your app locally, sending it out to select beta testers, or launching your app live to the app stores, you'll always find yourself debugging issues. It's useful to split errors into two categories: 14434d8818SAman Mittal 15434d8818SAman Mittal- Errors you encounter in the development 16434d8818SAman Mittal- Errors you (or your users) encounter in production 17434d8818SAman Mittal 18434d8818SAman MittalLet's go through recommended practices when dealing with each of the above situations. 19434d8818SAman Mittal 20434d8818SAman Mittal## Development errors 21434d8818SAman Mittal 22d92bb961SAman MittalThey are common errors that you encounter while developing your app. Delving into them isn't always straightforward. Usually, debugging when running your app with [Expo CLI](/more/expo-cli/) is enough. 23434d8818SAman Mittal 24434d8818SAman MittalOne way you can debug these issues is by looking at the [stack trace](/debugging/errors-and-warnings/#stack-traces). However, in some scenarios, looking at the stack trace isn't enough as the error message traced might be a little more cryptic. For such errors, follow the steps below: 25434d8818SAman Mittal 26434d8818SAman Mittal- Search for the error message in Google and [Stack Overflow](https://stackoverflow.com/questions), it's likely you're not the first person to ever run into this. 27434d8818SAman Mittal- **Isolate the code that's throwing the error**. This step is _vital_ in fixing obscure errors. To do this: 28434d8818SAman Mittal - Revert to a working version of your code. This may even be a completely blank `npx create-expo-app` project. 29434d8818SAman Mittal - Apply your recent changes piece by piece, until it breaks. 30434d8818SAman Mittal - If the code you're adding in each "piece" is complex, you may want to simplify what you're doing. For example, if you use a state management library such as Redux, you can try removing that from the equation completely to see if the issue lies in your state management (which is common in React apps). 31434d8818SAman Mittal - This should narrow down the possible sources of the error, and provide you with more information to search the internet for others who have had the same problem. 32434d8818SAman Mittal- Use breakpoints (or `console.log`s) to check and make sure a certain piece of code is being run, or that a variable has a certain value. Using `console.log` for debugging isn't considered the best practice, however, it's fast, easy, and oftentimes provides some illuminating information. 33434d8818SAman Mittal 34434d8818SAman MittalSimplifying code as much as possible to track down the source of error is a great way to debug your app and it gets exponentially easier. That's why many open-source repositories require a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) when you open an issue. It ensures you have isolated the issue and identified exactly where the problem occurs. If your app is too large and complex to do that, try and extract the functionality you're trying to add in a blank `npx create-expo-app` project, and go from there. 35434d8818SAman Mittal 36434d8818SAman Mittal### Native debugging 37434d8818SAman Mittal 38434d8818SAman MittalYou can perform full native debugging with Android Studio and Xcode by generating source code locally and building from that source. 39434d8818SAman Mittal 40434d8818SAman Mittal#### Android Studio 41434d8818SAman Mittal 42434d8818SAman Mittal<Step label="1"> 43434d8818SAman Mittal 44434d8818SAman MittalGenerate the native code for your project by running the following command: 45434d8818SAman Mittal 46434d8818SAman Mittal<Terminal cmd={['$ npx expo prebuild -p android']} /> 47434d8818SAman Mittal 48434d8818SAman MittalThis will add an **android** directory at the root of your project. 49434d8818SAman Mittal 50434d8818SAman Mittal</Step> 51434d8818SAman Mittal 52434d8818SAman Mittal<Step label="2"> 53434d8818SAman Mittal 54434d8818SAman MittalOpen the project in Android Studio by running the command: 55434d8818SAman Mittal 56434d8818SAman Mittal<Terminal cmd={['$ open -a /Applications/Android Studio.app ./android']} /> 57434d8818SAman Mittal 58434d8818SAman Mittal</Step> 59434d8818SAman Mittal 60434d8818SAman Mittal<Step label="3"> 61434d8818SAman Mittal 62434d8818SAman MittalBuild the app from Android Studio and connect the debugger. See [Google's documentation](https://developer.android.com/studio/debug#startdebug) for more information. 63434d8818SAman Mittal 64434d8818SAman Mittal</Step> 65434d8818SAman Mittal 66434d8818SAman Mittal> You can delete the **android** directory when you are done with this process. This ensures that your project remains managed by Expo CLI. Keeping the directory around and manually modifying it outside of `npx expo prebuild` means you'll need to manually upgrade and configure native libraries yourself (which is bare workflow). 67434d8818SAman Mittal 68434d8818SAman Mittal#### Xcode 69434d8818SAman Mittal 70434d8818SAman Mittal> This is only available for macOS users and requires Xcode to be installed. 71434d8818SAman Mittal 72434d8818SAman Mittal<Step label="1"> 73434d8818SAman Mittal 74434d8818SAman MittalGenerate the native code for your project by running the following command: 75434d8818SAman Mittal 76434d8818SAman Mittal<Terminal cmd={['$ npx expo prebuild -p ios']} /> 77434d8818SAman Mittal 78434d8818SAman MittalThis will add an **ios** directory at the root of your project. 79434d8818SAman Mittal 80434d8818SAman Mittal</Step> 81434d8818SAman Mittal 82434d8818SAman Mittal<Step label="2"> 83434d8818SAman Mittal 84434d8818SAman MittalOpen the project in Xcode by running the command which is a shortcut to open the `.xcworkspace` file from your project's **ios** directory in Xcode. 85434d8818SAman Mittal 86434d8818SAman Mittal<Terminal cmd={['$ xed ios']} /> 87434d8818SAman Mittal 88434d8818SAman Mittal</Step> 89434d8818SAman Mittal 90434d8818SAman Mittal<Step label="3"> 91434d8818SAman Mittal 92434d8818SAman MittalBuild the app with <kbd>Cmd ⌘</kbd> + <kbd>r</kbd> or by pressing the play button in the upper left corner of Xcode. 93434d8818SAman Mittal 94434d8818SAman Mittal</Step> 95434d8818SAman Mittal 96434d8818SAman Mittal<Step label="4"> 97434d8818SAman Mittal 98434d8818SAman MittalYou can now utilize [**Low-level debugger (LLDB)**](https://developer.apple.com/library/archive/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/Introduction.html) and all of the other [Xcode debugging tools](https://developer.apple.com/documentation/metal/debugging_tools) to examine the native runtime. 99434d8818SAman Mittal 100434d8818SAman Mittal</Step> 101434d8818SAman Mittal 102434d8818SAman Mittal> You can delete the **ios** directory when you are done with this process. This ensures that your project remains managed by Expo CLI. Keeping the directory around and manually modifying it outside of `npx expo prebuild` means you'll need to manually upgrade and configure native libraries yourself (which is bare workflow). 103434d8818SAman Mittal 104434d8818SAman Mittal## Production errors 105434d8818SAman Mittal 106434d8818SAman MittalErrors or bugs in your production app can be much harder to solve, mainly because you have less context around the error (that is, where, how, and why did the error occur?). 107434d8818SAman Mittal 108434d8818SAman Mittal**The best first step in addressing a production error is to reproduce it locally.** Once you reproduce an error locally, you can follow the [development debugging process](#development-errors) to isolate and address the root cause. 109434d8818SAman Mittal 110434d8818SAman Mittal> **Tip**: Sometimes, running your app in **production mode** locally will show errors that normally wouldn't be thrown. You can run the app locally in production by running `npx expo start --no-dev --minify`. 111434d8818SAman Mittal> `--no-dev` tells the server not to be run in development mode, and `--minify` is used to minify your code the same way it is for production JavaScript bundles. 112434d8818SAman Mittal 113434d8818SAman Mittal### Production app is crashing 114434d8818SAman Mittal 115434d8818SAman MittalIt can be a frustrating scenario when a production app crashes. There is very little information to look into when it happens. It's important to reproduce the issue, and even if you can't do that, to find any related crash reports. 116434d8818SAman Mittal 117434d8818SAman MittalStart by reproducing the crash using your production app and then **find an associated crash report**. 118434d8818SAman Mittal 119434d8818SAman Mittal#### Crash reports using adb logcat 120434d8818SAman Mittal 121434d8818SAman MittalIf your Android app is on Google Play, refer to the crashes section of the [Google Play Console](https://play.google.com/console/about/), or connect your Android device to your computer and run the following command: 122434d8818SAman Mittal 123434d8818SAman Mittal<Terminal cmd={['$ adb logcat']} /> 124434d8818SAman Mittal 125434d8818SAman MittalThe Android Debug Bridge (`adb`) program is part of the Android SDK and allows you to view streaming logs. An alternative to avoid installing Android SDK is to use [WebADB](https://webadb.com/) in Chrome. 126434d8818SAman Mittal 127434d8818SAman Mittal#### Crash reports using Console app 128434d8818SAman Mittal 129434d8818SAman MittalIf your iOS app is on TestFlight or the App Store, you can use the [Crashes Organizer](https://developer.apple.com/news/?id=nra79npr) in Xcode. 130434d8818SAman Mittal 131434d8818SAman MittalIf not, you can use the **Console** app in Xcode by connecting your device to your mac. Follow the steps below on how to access the Console app: 132434d8818SAman Mittal 133434d8818SAman Mittal<Step label="1"> 134434d8818SAman Mittal 135434d8818SAman MittalOpen Xcode app, and then open **Devices and Simulators** window by pressing <kbd>Shift</kbd> + <kbd>Cmd ⌘</kbd> + <kbd>2</kbd>. 136434d8818SAman Mittal 137434d8818SAman Mittal</Step> 138434d8818SAman Mittal 139434d8818SAman Mittal<Step label="2"> 140434d8818SAman Mittal 141434d8818SAman MittalIf you've connected a physical device, select it under **Devices**. Otherwise, if you are using a simulator, select it under **Simulators**. 142434d8818SAman Mittal 143434d8818SAman Mittal<ImageSpotlight 144434d8818SAman Mittal alt="Devices and Simulators window in Xcode." 145434d8818SAman Mittal src="/static/images/debugging/devices-simulators.png" 146434d8818SAman Mittal/> 147434d8818SAman Mittal 148434d8818SAman Mittal</Step> 149434d8818SAman Mittal 150434d8818SAman Mittal<Step label="3"> 151434d8818SAman Mittal 152434d8818SAman MittalClick on **Open Console** button shown in the window to open the console app. 153434d8818SAman Mittal 154434d8818SAman Mittal<ImageSpotlight 155434d8818SAman Mittal alt="Devices and Simulators window in Xcode." 156434d8818SAman Mittal src="/static/images/debugging/open-console.png" 157434d8818SAman Mittal/> 158434d8818SAman Mittal 159434d8818SAman MittalThis will open the console app for you to view logs from your device or simulator. 160434d8818SAman Mittal 161434d8818SAman Mittal</Step> 162434d8818SAman Mittal 163434d8818SAman MittalFor more information, see Apple's [Diagnosing Issues Using Crash Reports and Device Logs](https://developer.apple.com/documentation/xcode/diagnosing-issues-using-crash-reports-and-device-logs) guide. 164434d8818SAman Mittal 165434d8818SAman Mittal### App crashes on certain (older) devices 166434d8818SAman Mittal 167434d8818SAman MittalThis might indicate that there is a performance issue. You likely need to run your app through a profiler to get a better idea of what processes are killing the app, and [React Native provides some great documentation for this](https://reactnative.dev/docs/profiling). We also recommend using [React DevTools](https://www.npmjs.com/package/react-devtools) and the included profiler, which makes it super easy to identify performance sinks in your app. 168434d8818SAman Mittal 169434d8818SAman Mittal## Stuck? 170434d8818SAman Mittal 171434d8818SAman MittalThe Expo community and the React and React Native communities are great resources for help when you get stuck. There's a good chance someone else has run into the same error as you, so make sure to read the documentation, search the [forums](https://forums.expo.dev/), [GitHub issues](https://github.com/expo/expo/issues/), and [Stack Overflow](https://stackoverflow.com/). 172434d8818SAman Mittal 173434d8818SAman Mittal## Next step 174434d8818SAman Mittal 175434d8818SAman Mittal<BoxLink 176434d8818SAman Mittal title="Debugging tools" 177434d8818SAman Mittal description="Learn about different tools available to debug runtime issues in your Expo project." 178434d8818SAman Mittal href="/debugging/tools" 179*fa939da8SAman Mittal Icon={BookOpen02Icon} 180434d8818SAman Mittal/> 181