Created
August 31, 2017 11:02
-
-
Save KevCui/7d6760f8bf2e711028ca3de196fd98e7 to your computer and use it in GitHub Desktop.
Allow proxy mock for Android 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
root=$1 | |
dir="$root/android/src/main/" | |
xml="$dir/res/xml/network_security_config.xml" | |
manifest="$dir/AndroidManifest.xml" | |
tmpfile="$manifest.tmp" | |
if [ ! -e $manifest ]; then | |
echo "File $manifest doesn't exist!" | |
exit 1 | |
fi | |
if [ `grep "networkSecurityConfig" $manifest` ]; then | |
echo "File $manifest has already been modified!" | |
exit 1 | |
fi | |
# Edit AndroidManifest.xml | |
cp $manifest $tmpfile | |
cat $tmpfile | sed -e "/<application/a\\ | |
android\:networkSecurityConfig=\"@xml\/network_security_config\"" > $manifest | |
rm $tmpfile | |
# Add xml | |
echo '<?xml version="1.0" encoding="utf-8"?> | |
<network-security-config> | |
<base-config> | |
<trust-anchors> | |
<certificates src="system" /> | |
</trust-anchors> | |
</base-config> | |
<debug-overrides> | |
<trust-anchors> | |
<certificates src="user" /> | |
</trust-anchors> | |
</debug-overrides> | |
</network-security-config>' > $xml | |
echo "DONE!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment