How to create a configuration to run with $ ionic cordova emulate android -l -c local and let the emulator connect to host PC, accessing through 10.0.2.2 instead if localhost.
Create the file environment.local.emulator.ts. Then appli these changes to angular.json.
-
Add this snippet under
project.app.architect.build.configurations:"local-emulator": { "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.local.emulator.ts" } ] },
-
Add this under
project.app.architect.serve.configurations:"local-emulator": { "browserTarget": "app:build:local-emulator" },
-
Add this under
project.app.architect.ionic-cordova-build.configurations:"local": { "browserTarget": "app:build:local-emulator" }
-
Add this under
project.app.architect.ionic-cordova-serve.configurations:"local": { "cordovaBuildTarget": "app:ionic-cordova-build:local", "devServerTarget": "app:serve:local-emulator" },
Enable connections to host PC through 10.0.2.2.
-
Add this to
config.xml:<resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
2 Add this to resources/android/xml/network_security_config.xml (or create it if it does not exist):
```xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">10.0.2.2</domain> <!-- Add this line to enable connecting to host PC -->
</domain-config>
</network-security-config>
```