Skip to content

Commit

Permalink
fix(android): respect ANDROID_AVD_HOME environment variable (#1778)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvanengelen authored and noomorph committed Jan 3, 2020
1 parent 3f3e691 commit e560bac
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion detox/src/devices/drivers/EmulatorDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ class EmulatorDriver extends AndroidDriver {
}

async _fixEmulatorConfigIniSkinNameIfNeeded(avdName) {
const configFile = `${os.homedir()}/.android/avd/${avdName}.avd/config.ini`;
const avdHome = environment.getAvdHome();
const configFile = path.join(avdHome, `${avdName}.avd`, 'config.ini');
const config = ini.parse(fs.readFileSync(configFile, 'utf-8'));

if (!config['skin.name']) {
Expand Down
13 changes: 13 additions & 0 deletions detox/src/utils/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ function getAndroidSDKPath() {
return process.env.ANDROID_SDK_ROOT || process.env.ANDROID_HOME || '';
}

function getAndroidSDKHome() {
return process.env['ANDROID_SDK_HOME'] || os.homedir();
}

function getEmulatorHome() {
return process.env['ANDROID_EMULATOR_HOME'] || path.join(getAndroidSDKHome(), '.android');
}

function getAvdHome() {
return process.env['ANDROID_AVD_HOME'] || path.join(getEmulatorHome(), 'avd');
}

function getAndroidEmulatorPath() {
const sdkRoot = getAndroidSDKPath();
if (!sdkRoot) {
Expand Down Expand Up @@ -126,6 +138,7 @@ function getHomeDir() {
module.exports = {
getAaptPath,
getAdbPath,
getAvdHome,
getDetoxVersion,
getFrameworkPath,
getAndroidSDKPath,
Expand Down
22 changes: 22 additions & 0 deletions detox/src/utils/environment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ describe('Environment', () => {
await fs.remove(tempSdkPath);
});

describe('getAvdHome', () => {
const testCases = [
[path.join(os.homedir(), '.android', 'avd'), null, null, null],
[path.join('homedir', '.android', 'avd'), null, null, 'homedir'],
[path.join('emu', 'avd'), null, 'emu', 'homedir'],
['AVD', 'AVD', 'emu', 'homedir'],
];

it.each(testCases)('should return %j ' + [
'if $ANDROID_AVD_HOME = %j',
'if $ANDROID_EMULATOR_HOME = %j',
'if $ANDROID_SDK_HOME = %j',
].join(' and '), (...args) => {

process.env['ANDROID_AVD_HOME'] = args[1];
process.env['ANDROID_EMULATOR_HOME'] = args[2];
process.env['ANDROID_SDK_HOME'] = args[3];

expect(Environment.getAvdHome()).toBe(args[0]);
});
});

describe('getAndroidSDKPath', () => {
it(`should return empty string if $ANDROID_SDK_ROOT and $ANDROID_HOME both are not set`, () => {
delete process.env.ANDROID_SDK_ROOT;
Expand Down

0 comments on commit e560bac

Please sign in to comment.