use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidRunConfigurationBase method canInstantRun.
@NotNull
private InstantRunGradleSupport canInstantRun(@NotNull Module module, @NotNull List<AndroidDevice> targetDevices) {
if (targetDevices.size() != 1) {
return CANNOT_BUILD_FOR_MULTIPLE_DEVICES;
}
AndroidDevice device = targetDevices.get(0);
AndroidVersion version = device.getVersion();
if (!InstantRunManager.isInstantRunCapableDeviceVersion(version)) {
return API_TOO_LOW_FOR_INSTANT_RUN;
}
IDevice targetDevice = MakeBeforeRunTaskProvider.getLaunchedDevice(device);
if (targetDevice != null) {
if (MultiUserUtils.hasMultipleUsers(targetDevice, 200, TimeUnit.MILLISECONDS, false)) {
if (// run config explicitly specifies launching as a different user
getUserIdFromAmParameters() != MultiUserUtils.PRIMARY_USERID || !MultiUserUtils.isCurrentUserThePrimaryUser(targetDevice, 200, TimeUnit.MILLISECONDS, true)) {
// activity manager says current user is not primary
return CANNOT_DEPLOY_FOR_SECONDARY_USER;
}
}
}
InstantRunGradleSupport irSupportStatus = InstantRunGradleUtils.getIrSupportStatus(InstantRunGradleUtils.getAppModel(module), version);
if (irSupportStatus != SUPPORTED) {
return irSupportStatus;
}
// Gradle will instrument against the runtime android.jar (see commit 353f46cbc7363e3fca44c53a6dc0b4d17347a6ac).
// This means that the SDK platform corresponding to the device needs to be installed, otherwise the build will fail.
// We do this as the last check because it is actually possible to recover from this failure. In the future, maybe issues
// that have fixes will have to be handled in a more generic way.
AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform == null) {
return SUPPORTED;
}
IAndroidTarget[] targets = platform.getSdkData().getTargets();
for (int i = targets.length - 1; i >= 0; i--) {
if (!targets[i].isPlatform()) {
continue;
}
if (targets[i].getVersion().equals(version)) {
return SUPPORTED;
}
}
return TARGET_PLATFORM_NOT_INSTALLED;
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class EmulatorTargetChooser method chooseAvd.
@Nullable
private String chooseAvd() {
IAndroidTarget buildTarget = myFacet.getConfiguration().getAndroidTarget();
assert buildTarget != null;
AvdInfo[] avds = myFacet.getValidCompatibleAvds();
if (avds.length > 0) {
return avds[0].getName();
}
final Project project = myFacet.getModule().getProject();
AvdManager manager;
try {
manager = myFacet.getAvdManager(new AvdManagerLog() {
@Override
public void error(Throwable t, String errorFormat, Object... args) {
super.error(t, errorFormat, args);
if (errorFormat != null) {
final String msg = String.format(errorFormat, args);
LOG.error(msg);
}
}
});
} catch (final AndroidLocation.AndroidLocationException e) {
LOG.info(e);
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
}
});
return null;
}
final AvdManager finalManager = manager;
assert finalManager != null;
return UIUtil.invokeAndWaitIfNeeded(new Computable<String>() {
@Override
public String compute() {
int result = Messages.showDialog(project, "To run using the emulator, you must have an AVD defined.", "Define AVD", new String[] { "Cancel", "Create AVD" }, 1, null);
AvdInfo createdAvd = null;
if (result == 1) {
AvdOptionsModel avdOptionsModel = new AvdOptionsModel(null);
ModelWizardDialog dialog = AvdWizardUtils.createAvdWizard(null, project, avdOptionsModel);
if (dialog.showAndGet()) {
createdAvd = avdOptionsModel.getCreatedAvd();
}
}
return createdAvd == null ? null : createdAvd.getName();
}
});
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class StateListPicker method doValidate.
/**
* Returns a {@link ValidationInfo} in the case one of the state list state has a value that does not resolve to a valid resource,
* or a value that is a private framework value. or if one of the state list component requires an API level higher than minApi.
*/
@Nullable
public /*if there is no error*/
ValidationInfo doValidate(int minApi) {
IAndroidTarget target = myConfiguration.getRealTarget();
assert target != null;
final AndroidTargetData androidTargetData = AndroidTargetData.getTargetData(target, myModule);
assert androidTargetData != null;
ResourceRepository frameworkResources = myConfiguration.getFrameworkResources();
assert frameworkResources != null;
for (StateComponent component : myStateComponents) {
ValidationInfo error = component.doValidate(minApi, androidTargetData);
if (error != null) {
return error;
}
}
return null;
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class RenderErrorContributorTest method getRenderOutput.
private List<RenderErrorModel.Issue> getRenderOutput(@NotNull VirtualFile file, @Nullable LogOperation logOperation) {
assertNotNull(file);
AndroidFacet facet = AndroidFacet.getInstance(myModule);
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
assertNotNull(psiFile);
assertNotNull(facet);
ConfigurationManager configurationManager = facet.getConfigurationManager();
assertNotNull(configurationManager);
IAndroidTarget target = getTestTarget(configurationManager);
assertNotNull(target);
configurationManager.setTarget(target);
Configuration configuration = configurationManager.getConfiguration(file);
assertSame(target, configuration.getRealTarget());
if (!LayoutLibraryLoader.USE_SDK_LAYOUTLIB) {
// TODO: Remove this after http://b.android.com/203392 is released
// If we are using the embedded layoutlib, use a recent theme to avoid missing styles errors.
configuration.setTheme("android:Theme.Material");
}
RenderService renderService = RenderService.get(facet);
RenderLogger logger = renderService.createLogger();
final RenderTask task = renderService.createTask(psiFile, configuration, logger, null);
assertNotNull(task);
task.disableSecurityManager();
RenderResult render = RenderTestBase.renderOnSeparateThread(task);
assertNotNull(render);
if (logOperation != null) {
logOperation.addErrors(logger, render);
}
return RenderErrorModelFactory.createErrorModel(render, null).getIssues().stream().sorted().collect(Collectors.toList());
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class RenderErrorContributorTest method getTestTarget.
@Nullable
private IAndroidTarget getTestTarget(@NotNull ConfigurationManager configurationManager) {
String platformDir = TestUtils.getLatestAndroidPlatform();
for (IAndroidTarget target : configurationManager.getTargets()) {
if (!ConfigurationManager.isLayoutLibTarget(target)) {
continue;
}
String path = target.getPath(IAndroidTarget.ANDROID_JAR);
if (path == null) {
continue;
}
File f = new File(path);
if (f.getParentFile() != null && f.getParentFile().getName().equals(platformDir)) {
return target;
}
}
return null;
}
Aggregations