Search in sources :

Example 66 with AndroidVersion

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);
}
Also used : OpenAndroidSdkManagerHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenAndroidSdkManagerHyperlink) ArrayList(java.util.ArrayList) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) AndroidVersion(com.android.sdklib.AndroidVersion) InstallPlatformHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.InstallPlatformHyperlink) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink)

Example 67 with AndroidVersion

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);
}
Also used : IdeaSourceProvider(org.jetbrains.android.facet.IdeaSourceProvider) SourceProvider(com.android.builder.model.SourceProvider) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AndroidModuleInfo(com.android.tools.idea.model.AndroidModuleInfo) Module(com.intellij.openapi.module.Module) TemplateMetadata(com.android.tools.idea.templates.TemplateMetadata)

Example 68 with AndroidVersion

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);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 69 with AndroidVersion

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;
}
Also used : IDevice(com.android.ddmlib.IDevice) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) InstantRunGradleSupport(com.android.tools.idea.fd.gradle.InstantRunGradleSupport) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with AndroidVersion

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());
}
Also used : AndroidVersion(com.android.sdklib.AndroidVersion)

Aggregations

AndroidVersion (com.android.sdklib.AndroidVersion)89 Test (org.junit.Test)21 NotNull (org.jetbrains.annotations.NotNull)14 IAndroidTarget (com.android.sdklib.IAndroidTarget)12 IDevice (com.android.ddmlib.IDevice)11 Nullable (org.jetbrains.annotations.Nullable)9 MockPlatformTarget (com.android.sdklib.internal.androidTarget.MockPlatformTarget)8 Module (com.intellij.openapi.module.Module)8 File (java.io.File)8 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)8 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)8 DetailsTypes (com.android.sdklib.repository.meta.DetailsTypes)6 Project (com.intellij.openapi.project.Project)5 Abi (com.android.sdklib.devices.Abi)4 InstantRunGradleSupport (com.android.tools.idea.fd.gradle.InstantRunGradleSupport)4 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)4 OutputFile (com.android.build.OutputFile)3 TypeDetails (com.android.repository.impl.meta.TypeDetails)3 AvdInfo (com.android.sdklib.internal.avd.AvdInfo)3 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)3