Search in sources :

Example 21 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class LintIdeClient method getBuildTools.

@Override
@Nullable
public BuildToolInfo getBuildTools(@NonNull com.android.tools.lint.detector.api.Project project) {
    if (project.isGradleProject()) {
        Module module = getModule();
        if (module != null) {
            AndroidModuleModel model = AndroidModuleModel.get(module);
            if (model != null) {
                GradleVersion version = model.getModelVersion();
                if (version != null && version.isAtLeast(2, 1, 0)) {
                    String buildToolsVersion = model.getAndroidProject().getBuildToolsVersion();
                    AndroidSdkHandler sdk = getSdk();
                    if (sdk != null) {
                        try {
                            Revision revision = Revision.parseRevision(buildToolsVersion);
                            BuildToolInfo buildToolInfo = sdk.getBuildToolInfo(revision, getRepositoryLogger());
                            if (buildToolInfo != null) {
                                return buildToolInfo;
                            }
                        } catch (NumberFormatException ignore) {
                        // Fall through and use the latest
                        }
                    }
                }
            }
        }
    }
    return super.getBuildTools(project);
}
Also used : Revision(com.android.repository.Revision) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Module(com.intellij.openapi.module.Module) GradleVersion(com.android.ide.common.repository.GradleVersion) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class AvdWizardUtils method resolveSkinPath.

@Nullable
public static File resolveSkinPath(@Nullable File path, @Nullable SystemImageDescription image, @NotNull FileOp fop) {
    if (path == null || path.getPath().isEmpty()) {
        return path;
    }
    if (FileUtil.filesEqual(path, NO_SKIN)) {
        return NO_SKIN;
    }
    if (!path.isAbsolute()) {
        if (image != null) {
            File[] skins = image.getSkins();
            for (File skin : skins) {
                if (skin.getPath().endsWith(File.separator + path.getPath())) {
                    return skin;
                }
            }
        }
        AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
        File dest = null;
        if (sdkData != null) {
            File sdkDir = sdkData.getLocation();
            File sdkSkinDir = new File(sdkDir, "skins");
            dest = new File(sdkSkinDir, path.getPath());
            if (fop.exists(dest)) {
                return dest;
            }
        }
        File resourceDir = DeviceArtDescriptor.getBundledDescriptorsFolder();
        if (resourceDir != null) {
            File resourcePath = new File(resourceDir, path.getPath());
            if (!fop.exists(resourcePath)) {
                String name = resourcePath.getName();
                // Unfortunately these have a different name than that included in the system images, so remap if necessary.
                if (name.equals("AndroidWearSquare")) {
                    resourcePath = new File(resourcePath.getParent(), "wear_square");
                }
                if (name.equals("AndroidWearRound")) {
                    resourcePath = new File(resourcePath.getParent(), "wear_round");
                }
            }
            if (fop.exists(resourcePath)) {
                if (dest != null) {
                    try {
                        // Convert from webp to png here since emulator appears not to support it
                        fop.mkdirs(dest);
                        // Convert skin files (which are in webp format) to PNG for older versions of the emulator?
                        // As of 25.2.3, emulator supports webp directly.
                        AndroidSdkHandler sdkHandler = sdkData.getSdkHandler();
                        if (!emulatorSupportsWebp(sdkHandler)) {
                            convertWebpSkinToPng(fop, dest, resourcePath);
                        } else {
                            // Normal copy
                            for (File src : fop.listFiles(resourcePath)) {
                                File target = new File(dest, src.getName());
                                if (fop.isFile(src) && !fop.exists(target)) {
                                    fop.copyFile(src, target);
                                }
                            }
                        }
                        return dest;
                    } catch (IOException e) {
                        getLog().warn(String.format("Failed to copy skin directory to %1$s, using studio-relative path %2$s", dest, resourcePath));
                    }
                }
                return resourcePath;
            }
        }
    }
    return path;
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class SkinChooser method getSkins.

private List<File> getSkins() {
    List<Device> devices = DeviceManagerConnection.getDefaultDeviceManagerConnection().getDevices();
    Set<File> result = Sets.newTreeSet();
    for (Device device : devices) {
        File skinFile = AvdWizardUtils.resolveSkinPath(device.getDefaultHardware().getSkinFile(), null, FileOpUtils.create());
        if (skinFile != null && skinFile.exists()) {
            result.add(skinFile);
        }
    }
    StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(SkinChooser.class);
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    for (IAndroidTarget target : sdkHandler.getAndroidTargetManager(progress).getTargets(progress)) {
        Arrays.stream(target.getSkins()).map(this::resolve).forEach(result::add);
    }
    for (ISystemImage img : sdkHandler.getSystemImageManager(progress).getImages()) {
        Arrays.stream(img.getSkins()).map(this::resolve).forEach(result::add);
    }
    List<File> resultList = Lists.newArrayList();
    resultList.add(NO_SKIN);
    resultList.addAll(result);
    return resultList;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Device(com.android.sdklib.devices.Device) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) IAndroidTarget(com.android.sdklib.IAndroidTarget) ISystemImage(com.android.sdklib.ISystemImage) File(java.io.File)

Example 24 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class ChooseActivityTypeStep method initTemplateValues.

private static void initTemplateValues(@NotNull Map<String, Object> templateValues, @Nullable Project project) {
    templateValues.put(ATTR_GRADLE_PLUGIN_VERSION, determineGradlePluginVersion(project));
    templateValues.put(ATTR_GRADLE_VERSION, SdkConstants.GRADLE_LATEST_VERSION);
    templateValues.put(ATTR_IS_GRADLE, true);
    // TODO: Check if this is used at all by the templates
    templateValues.put("target.files", new HashSet<>());
    templateValues.put("files.to.open", new ArrayList<>());
    // TODO: Implement Instant App code
    String whSdkLocation = System.getenv(WH_SDK_ENV_VAR);
    templateValues.put(ATTR_WH_SDK, whSdkLocation + "/tools/resources/shared-libs");
    templateValues.put("whSdkEnabled", isNotEmpty(whSdkLocation));
    templateValues.put("alsoCreateIapk", false);
    templateValues.put("isInstantApp", false);
    // TODO: Check this one with Joe. It seems to be used by the old code on Import module, but can't find it on new code
    templateValues.put(ATTR_CREATE_ACTIVITY, false);
    templateValues.put(ATTR_PER_MODULE_REPOS, false);
    // TODO: This seems project stuff
    if (project != null) {
        templateValues.put(ATTR_TOP_OUT, project.getBasePath());
    }
    String mavenUrl = System.getProperty(TemplateWizard.MAVEN_URL_PROPERTY);
    if (mavenUrl != null) {
        templateValues.put(ATTR_MAVEN_URL, mavenUrl);
    }
    final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    BuildToolInfo buildTool = sdkHandler.getLatestBuildTool(new StudioLoggerProgressIndicator(ConfigureAndroidModuleStep.class), false);
    if (buildTool != null) {
        // If buildTool is null, the template will use buildApi instead, which might be good enough.
        templateValues.put(ATTR_BUILD_TOOLS_VERSION, buildTool.getRevision().toString());
    }
    File sdkLocation = sdkHandler.getLocation();
    if (sdkLocation != null) {
        // Gradle expects a platform-neutral path
        templateValues.put(ATTR_SDK_DIR, FileUtil.toSystemIndependentName(sdkLocation.getPath()));
        String espressoVersion = RepositoryUrlManager.get().getLibraryRevision(SupportLibrary.ESPRESSO_CORE.getGroupId(), SupportLibrary.ESPRESSO_CORE.getArtifactId(), null, false, sdkLocation, FileOpUtils.create());
        if (espressoVersion != null) {
            // TODO: Is this something that should be on the template (TemplateMetadata.ATTR_)?
            // Check with Jens, or at least send an email to verify template variables. We may also need to port some old dynamic step.
            templateValues.put("espressoVersion", espressoVersion);
        }
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) ConfigureAndroidModuleStep(com.android.tools.idea.npw.module.ConfigureAndroidModuleStep) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 25 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class AndroidSdkInitializer method run.

@Override
public void run() {
    if (!isAndroidSdkManagerEnabled()) {
        return;
    }
    // If running in a GUI test we don't want the "Select SDK" dialog to show up when running GUI tests.
    if (isGuiTestingMode()) {
        // This is good enough. Later on in the GUI test we'll validate the given SDK path.
        return;
    }
    IdeSdks ideSdks = IdeSdks.getInstance();
    File androidSdkPath = ideSdks.getAndroidSdkPath();
    if (androidSdkPath == null) {
        try {
            // Setup JDK and Android SDK if necessary
            setUpSdks();
            androidSdkPath = ideSdks.getAndroidSdkPath();
        } catch (Exception e) {
            LOG.error("Unexpected error while setting up SDKs: ", e);
        }
    }
    if (androidSdkPath != null) {
        AndroidSdkHandler handler = AndroidSdkHandler.getInstance(androidSdkPath);
        new PatchInstallingRestarter(handler, FileOpUtils.create()).restartAndInstallIfNecessary();
        // We need to start the system info monitoring even in case when user never
        // runs a single emulator instance: e.g., incompatible hypervisor might be
        // the reason why emulator is never run, and that's exactly the data
        // SystemInfoStatsMonitor collects
        new SystemInfoStatsMonitor().start();
    }
}
Also used : IdeSdks(com.android.tools.idea.sdk.IdeSdks) PatchInstallingRestarter(com.android.tools.idea.sdk.install.patch.PatchInstallingRestarter) SystemInfoStatsMonitor(com.android.tools.idea.sdk.SystemInfoStatsMonitor) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) File(java.io.File) IOException(java.io.IOException)

Aggregations

AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)38 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)23 File (java.io.File)11 Nullable (org.jetbrains.annotations.Nullable)11 RepoManager (com.android.repository.api.RepoManager)10 NotNull (org.jetbrains.annotations.NotNull)9 RemotePackage (com.android.repository.api.RemotePackage)8 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)8 ProgressIndicator (com.android.repository.api.ProgressIndicator)6 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)6 BuildToolInfo (com.android.sdklib.BuildToolInfo)6 IAndroidTarget (com.android.sdklib.IAndroidTarget)6 StudioProgressRunner (com.android.tools.idea.sdk.progress.StudioProgressRunner)6 ImmutableList (com.google.common.collect.ImmutableList)4 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)3 Revision (com.android.repository.Revision)3 LocalPackage (com.android.repository.api.LocalPackage)3 RepoPackage (com.android.repository.api.RepoPackage)3 FakeRepoManager (com.android.repository.testframework.FakeRepoManager)3 MockFileOp (com.android.repository.testframework.MockFileOp)3