Google chrome debugger tool also known as Chrome debug is used by many react native developers to debug react native android apps. Debug means checking the app for errors or API class data in the background using custom tool. The debug tool works with Console.log() method. The Console.log() method allow us to print any sending or coming value in debugger console. If we’re receiving data from a WEB API then we can print all the values in Console method and if the data not shown in the List View or FlatList then we can be sure using console that the data is arrived or not in the app using Api call. So in this tutorial we would learn about How to Debug React Native App in Android Emulator Using Chrome Debug Tool.
Contents in this project Debug React Native App in Android Emulator Using Chrome Debug Tool:-
1. The first step is to start the android emulator in your computer. Now start the NPM server or launch the react native app in your emulator. Make sure you have installed Google Chrome Web Browser in your computer.
2. To open the Debug menu we have to simulate the shack device functionality in our emulator. So if you’re using REAL android device then simply shack the device to open debug menu and if you’re using Android Emulator then press CTRL + M from your computer keyboard to open the debug menu. After opening the menu the menu would look like below screenshot.
3. Click on Debug to open the Chrome Debugger Tool in your computer. After opening the Debug tool in your Chrome in your computer look like this.
4. Now Right Click on the screen -> Inspect .
5. Now you can see the Debugger Console Window on the Right Side of Screen. Select Console TAB.
6. Here you can see two debug message first one is App Called… and in the another Console I’m printing the WEB API JSON data. In this console I’m printing one record only.
7. In below screen shot I’m printing the complete data in the JSON format.
This is how we can debug or react native android application in real device or android simulator.
8. Complete Source Code for App.js file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
import React, { useState, useEffect } from ‘react’;
import { View, StyleSheet, Text, LogBox } from ‘react-native’;
export default function App() {
//LogBox.ignoreLogs([‘Remote debugger’]);
useEffect(() => {
fetch(‘https://jsonplaceholder.typicode.com/posts’, {
method: ‘GET’,
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
})
.catch((error) => {
console.error(error);
});
}, []);
console.log(‘App Called…’);
return (
<View style={styleSheet.MainContainer}>
<Text style={styleSheet.text}>
Debug App in Android Emulator in React Native using Chrome Debugger Tool.
</Text>
</View>
);
}
const styleSheet = StyleSheet.create({
MainContainer: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’
},
text: {
textAlign: ‘center’,
fontSize: 27,
padding: 10
}
});
|
Screenshot of App: