if (descriptor == null) {
descriptor = Hudson.getInstance().getDescriptorByType(DescriptorImpl.class);
}
// Substitute environment and build variables into config
final EnvVars envVars = Utils.getEnvironment(build, listener);
final Map<String, String> buildVars = build.getBuildVariables();
// Device properties
String avdName = Utils.expandVariables(envVars, buildVars, this.avdName);
String osVersion = Utils.expandVariables(envVars, buildVars, this.osVersion);
String screenDensity = Utils.expandVariables(envVars, buildVars, this.screenDensity);
String screenResolution = Utils.expandVariables(envVars, buildVars, this.screenResolution);
String deviceLocale = Utils.expandVariables(envVars, buildVars, this.deviceLocale);
String sdCardSize = Utils.expandVariables(envVars, buildVars, this.sdCardSize);
if (sdCardSize != null) {
sdCardSize = sdCardSize.toUpperCase().replaceAll("[ B]", "");
}
String targetAbi = Utils.expandVariables(envVars, buildVars, this.targetAbi);
String avdNameSuffix = Utils.expandVariables(envVars, buildVars, this.avdNameSuffix);
// Expand macros within hardware property values
final int propCount = hardwareProperties == null ? 0 : hardwareProperties.length;
HardwareProperty[] expandedProperties = new HardwareProperty[propCount];
for (int i = 0; i < propCount; i++) {
HardwareProperty prop = hardwareProperties[i];
String expandedValue = Utils.expandVariables(envVars, buildVars, prop.value);
expandedProperties[i] = new HardwareProperty(prop.key, expandedValue);
}
// Emulator properties
String commandLineOptions = Utils.expandVariables(envVars, buildVars, this.commandLineOptions);
// SDK location
Node node = Computer.currentComputer().getNode();
String androidHome = Utils.expandVariables(envVars, buildVars, descriptor.androidHome);
androidHome = Utils.discoverAndroidHome(launcher, node, envVars, androidHome);
// Despite the nice inline checks and warnings when the user is editing the config,
// these are not binding, so the user may have saved invalid configuration.
// Here we check whether or not it's worth proceeding based on the saved values.
// As config variables aren't yet expanded, this check can't catch all possible errors.
String configError = isConfigValid(avdName, osVersion, screenDensity, screenResolution,
deviceLocale, sdCardSize);
if (configError != null) {
log(logger, Messages.ERROR_MISCONFIGURED(configError));
build.setResult(Result.NOT_BUILT);
return null;
}
// Build emulator config, ensuring that variables expand to valid SDK values
EmulatorConfig emuConfig;
boolean shouldKeepInWorkspace = descriptor.shouldKeepInWorkspace && Util.fixEmptyAndTrim(avdName) == null;
final String androidSdkHome = (envVars != null && shouldKeepInWorkspace ? envVars.get("WORKSPACE") : null);
try {
emuConfig = EmulatorConfig.create(avdName, osVersion, screenDensity,
screenResolution, deviceLocale, sdCardSize, wipeData, showWindow, useSnapshots,
commandLineOptions, targetAbi, androidSdkHome, executable, avdNameSuffix);
} catch (IllegalArgumentException e) {