use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class MissingPlatformErrorHandler method findAndAddQuickFixes.
private void findAndAddQuickFixes(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
String missingPlatform = getMissingPlatform(text);
if (missingPlatform == null) {
return;
}
String loadError = null;
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
AndroidSdkHandler sdkHandler = null;
AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (androidSdkData != null) {
sdkHandler = androidSdkData.getSdkHandler();
}
if (sdkHandler != null) {
AndroidVersion version = AndroidTargetHash.getPlatformVersion(missingPlatform);
if (version != null) {
// Is the platform installed?
ProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
loadError = sdkHandler.getAndroidTargetManager(logger).getErrorForPackage(DetailsTypes.getPlatformPath(version));
hyperlinks.add(new InstallPlatformHyperlink(version));
}
}
if (hyperlinks.isEmpty()) {
// We are unable to install platform automatically.
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
if (!facets.isEmpty()) {
// We can only open SDK manager if the project has an Android facet. Android facet has a reference to the Android SDK manager.
hyperlinks.add(new OpenAndroidSdkManagerHyperlink());
}
}
if (isNotEmpty(loadError)) {
text += "\nPossible cause: " + loadError;
}
SyncMessages.getInstance(project).updateNotification(notification, text, hyperlinks);
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class AddAndroidActivityPath method init.
@Override
protected void init() {
Module module = getModule();
assert module != null;
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null;
AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform != null) {
myState.put(KEY_BUILD_SDK, platform.getTarget().getVersion().getFeatureLevel());
}
AndroidModuleInfo moduleInfo = AndroidModuleInfo.get(facet);
AndroidVersion minSdkVersion = moduleInfo.getMinSdkVersion();
myState.put(KEY_MIN_SDK, minSdkVersion);
myState.put(KEY_TARGET_API, moduleInfo.getTargetSdkVersion());
myState.put(KEY_PACKAGE_NAME, getInitialPackageName(module, facet));
myState.put(KEY_OPEN_EDITORS, true);
if (myTemplate == null) {
FormFactor formFactor = getFormFactor(myTargetFolder);
myState.put(FormFactorUtils.getMinApiLevelKey(formFactor), minSdkVersion.getApiLevel());
myState.put(FormFactorUtils.getBuildApiLevelKey(formFactor), moduleInfo.getTargetSdkVersion().getApiLevel());
ActivityGalleryStep galleryStep = new ActivityGalleryStep(formFactor, false, KEY_SELECTED_TEMPLATE, module, myParentDisposable);
addStep(galleryStep);
} else {
TemplateMetadata templateMetadata = TemplateManager.getInstance().getTemplateMetadata(myTemplate);
assert templateMetadata != null;
myState.put(KEY_SELECTED_TEMPLATE, new TemplateEntry(myTemplate, templateMetadata));
}
SourceProvider[] sourceProviders = getSourceProviders(module, myTargetFolder);
boolean isInstantAppModule = facet.getProjectType() == PROJECT_TYPE_ATOM;
myState.put(IS_INSTANT_APP_KEY, isInstantAppModule);
myParameterStep = new TemplateParameterStep2(getFormFactor(myTargetFolder), ImmutableMap.of(), myParentDisposable, KEY_PACKAGE_NAME, sourceProviders, CUSTOMIZE_ACTIVITY_TITLE);
myAssetStudioStep = new IconStep(KEY_SELECTED_TEMPLATE, KEY_SOURCE_PROVIDER, myParentDisposable);
addStep(myParameterStep);
addStep(myAssetStudioStep);
}
use of com.android.sdklib.AndroidVersion in project android by JetBrains.
the class LaunchCompatibilityCheckerImpl method create.
public static LaunchCompatibilityChecker create(@NotNull AndroidFacet facet) {
AndroidVersion minSdkVersion = AndroidModuleInfo.get(facet).getRuntimeMinSdkVersion();
AndroidPlatform platform = facet.getConfiguration().getAndroidPlatform();
if (platform == null) {
throw new IllegalStateException("Android platform not set for module: " + facet.getModule().getName());
}
// Currently, we only look at whether the device supports the watch feature.
// We may not want to search the device for every possible feature, but only a small subset of important
// features, starting with hardware type watch.
EnumSet<IDevice.HardwareFeature> requiredHardwareFeatures;
if (LaunchUtils.isWatchFeatureRequired(facet)) {
requiredHardwareFeatures = EnumSet.of(IDevice.HardwareFeature.WATCH);
} else {
requiredHardwareFeatures = EnumSet.noneOf(IDevice.HardwareFeature.class);
}
Set<String> supportedAbis = facet.getAndroidModel() instanceof AndroidModuleModel ? ((AndroidModuleModel) facet.getAndroidModel()).getSelectedVariant().getMainArtifact().getAbiFilters() : null;
return new LaunchCompatibilityCheckerImpl(minSdkVersion, platform.getTarget(), requiredHardwareFeatures, supportedAbis);
}
use of com.android.sdklib.AndroidVersion 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.AndroidVersion in project android by JetBrains.
the class AndroidDeviceComparator method compare.
@Override
public int compare(@NotNull AndroidDevice device1, @NotNull AndroidDevice device2) {
// prefer devices that are running
if (device1.isRunning() != device2.isRunning()) {
return device1.isRunning() ? -1 : 1;
}
// prefer devices with higher API level
AndroidVersion version1 = device1.getVersion();
AndroidVersion version2 = device2.getVersion();
if (!version1.equals(version2)) {
return version2.compareTo(version1);
}
// prefer real devices to AVDs
if (device1.isVirtual() != device2.isVirtual()) {
return device1.isVirtual() ? 1 : -1;
}
// Provide a consistent ordering: use serial numbers to compare devices that are identical in other respects
return device1.getSerial().compareTo(device2.getSerial());
}
Aggregations