Help
How to Capture Network Logs in an Android Application?
Troubleshooting Steps
Section titled “Troubleshooting Steps”Step 1: Create a network security configuration XML file
Section titled “Step 1: Create a network security configuration XML file”-
Create the res/xml directory in your project if it does not exist.
-
Create a new XML file named network_security_config.xml.
-
Add the following content:
<network-security-config><base-config><trust-anchors><!-- Trust preinstalled CAs --><certificates src="system" /><!-- Trust user-added CAs (needed for proxies) --><certificates src="user" /></trust-anchors></base-config></network-security-config>
This configuration allows your app to trust user-installed certificates, enabling proxy tools to capture network logs.
Step 2: Update the Application Manifest File
Section titled “Step 2: Update the Application Manifest File”-
Open AndroidManifest.xml.
-
Locate the
tag. -
Add the android:networkSecurityConfig attribute:
<?xml version="1.0" encoding="utf-8"?><manifest ... ><application android:networkSecurityConfig="@xml/network_security_config">...</application></manifest>
Now, your app will use the specified network security configuration and allow network logs to be captured.