Skip to content

Commit 97eea37

Browse files
authored
fix: default ip for android emulators (#52)
1 parent 4ba5ee9 commit 97eea37

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

app/main-view-model.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference path="../declarations.d.ts"/>
2-
import { Observable, ObservableArray, Http, Device, Frame } from "@nativescript/core";
2+
import { Observable, ObservableArray, Http, Device, Frame, isAndroid } from "@nativescript/core";
33
import { KarmaHostResolver } from './services/karma-host-resolver';
44
import { KarmaFilesService } from './services/karma-files-service';
55
import { TestExecutionService } from './services/test-execution-service';
@@ -20,6 +20,17 @@ function enableSocketIoDebugging() {
2020

2121
var config: INetworkConfiguration = require('../config');
2222
config.options = config.options || {};
23+
// For whatever reason, Android emulators sometime struggle to find a
24+
// reachable host ip and make a successful call for the `context.json` file.
25+
// This happens in the test runner, even though mobile browsers can make successful calls to the
26+
// already discovered ips. According to
27+
// https://developer.android.com/studio/run/emulator-networking#networkaddresses
28+
// ip addr: `10.0.2.2` is a special alias to your host loopback interface
29+
// (i.e., 127.0.0.1 on your development machine)
30+
// adding this ipaddr eases the struggle. (no effect on actual devices)
31+
if (isAndroid)
32+
config.ips = (config.ips || []).concat(['10.0.2.2'])
33+
2334
if (!config.options.appDirectoryRelativePath) {
2435
config.options.appDirectoryRelativePath = "app";
2536
}

0 commit comments

Comments
 (0)