Skip to content

Instantly share code, notes, and snippets.

@RaschidJFR
Last active November 4, 2019 22:01
Show Gist options
  • Select an option

  • Save RaschidJFR/769d39cdbe8f986d29cd4ad9bc464345 to your computer and use it in GitHub Desktop.

Select an option

Save RaschidJFR/769d39cdbe8f986d29cd4ad9bc464345 to your computer and use it in GitHub Desktop.
Ionic v4: Configuration for connecting to local server database

Create a configuration for connecting to live reload with: ionic cordova emulate android -l -c local.

angular.json

Create the file environment.local.emulator.ts. Then appli these changes to angular.json.

  1. Add this snippet under project.app.architect.build.configurations:

    "local-emulator": {
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.local.emulator.ts"
        }
      ]
    },
  2. Add this under project.app.architect.serve.configurations:

    "local-emulator": {
      "browserTarget": "app:build:local-emulator"
    },
  3. Add this under project.app.architect.ionic-cordova-build.configurations:

    "local": {
      "browserTarget": "app:build:local-emulator"
    }
  4. Add this under project.app.architect.ionic-cordova-serve.configurations:

    "local": {
      "cordovaBuildTarget": "app:ionic-cordova-build:local",
      "devServerTarget": "app:serve:local-emulator"
    },

config.xml

Enable connections to host PC through 10.0.2.2.

  1. Add this under <platform name="android">

    <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
        <network-security-config>
            <domain-config cleartextTrafficPermitted="true">
                <domain includeSubdomains="true">10.0.2.2</domain>
            </domain-config>
        </network-security-config>
    </edit-config>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment