Skip to content

Commit

Permalink
android cli troubleshooting
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpoole committed Mar 14, 2024
1 parent 50ad7cc commit 49f52fd
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions website/docs/cli/commands/serve-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,47 @@ portals serve android \
- `--portal-name` **(string)** The name of the target Portal. (default "PORTAL")
- `--config` **(string)** config file (default $PWD/.portals.yaml)

### Troubleshooting connectivity issues

The Android emulator should be able to reach web servers running on the host machine through the IP address `10.0.2.2`. This sometimes may not work due to firewall policies, VPN settings, or other environmental changes. If you are having trouble connecting to your local web server from an emulator, try these troubleshooting steps.

#### Make sure your application supports Internet connectivity

The Android manifest file should contain the following permission

```xml
<uses-permission android:name="android.permission.INTERNET" />
```

#### Cleartext web content

If you are testing with an http server you may encounter an issue displaying a cleartext web page due to the default Android security settings. There are two ways to permit this content to load:

- Add `android:usesCleartextTraffic="true"` to your Android manifest `application` tag, or
- Create a more narrowly scoped [Network Security Config](https://developer.android.com/privacy-and-security/security-config#CleartextTrafficPermitted) that permits cleartext traffic on your specific test domain only.

#### Emulator network troubleshooting

If the local web server fails to load with errors like `net::ERR_CACHE_HIT` or `net::ERR_CONNECTION_REFUSED`, you may have network settings preventing the emulator/device from using Android’s loopback address. One way to confirm if this is your problem is to try loading your local web server from the emulator web browser. Double check that your local web server is actually running, then open Chrome in the emulator and go to the URL for your web app. If it loads, then the issue is related to your app specifically. If it does not load, then the emulator as a whole is having issues connecting to the web server on your local machine through the virtual network.

:::note

Reminder: the emulator does not reach your local development machine through the `localhost` url, as this is the loopback address for the emulator virtual machine itself. The IP address for your local machine from the emulator is `10.0.2.2`.

:::

If you are unable to reach your web server, try creating a proxy connection through the Android Debug Bridge app (adb). This is done using the terminal. For example:

To link `localhost:8080` on your emulator to `localhost:8080` on your development machine, open the terminal and run:

```sh
$ANDROID_HOME/platform-tools/adb reverse tcp:8080 tcp:8080
```

This will create a proxy through to the emulator and should allow the web content to load on the emulator through `localhost:8080` in the emulator web browser. Since the Portals CLI tries to be helpful by changing `localhost` to `10.0.2.2` in your app dev-server setting, you can force the localhost IP in your app by setting the development server to `127.0.0.1`, such as:

```bash
portals serve android \
--application /path/to/your/android-app.apk \
--dev-server http://127.0.0.1:8080
```

0 comments on commit 49f52fd

Please sign in to comment.