Search in sources :

Example 21 with AndroidSdkData

use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.

the class SdkQuickfixUtils method getSdkHandler.

private static AndroidSdkHandler getSdkHandler() {
    AndroidSdkData data = AndroidSdks.getInstance().tryToChooseAndroidSdk();
    if (data == null) {
        String title = "SDK Problem";
        String msg = "<html>" + "Your Android SDK is missing or out of date." + "<br>" + "You can configure your SDK via <b>Configure | Project Defaults | Project Structure | SDKs</b></html>";
        Messages.showErrorDialog(msg, title);
        return null;
    }
    return data.getSdkHandler();
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData)

Example 22 with AndroidSdkData

use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.

the class TemplateTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    myApiSensitiveTemplate = true;
    if (!ourValidatedTemplateManager) {
        ourValidatedTemplateManager = true;
        File templateRootFolder = TemplateManager.getTemplateRootFolder();
        if (templateRootFolder == null) {
            AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
            if (sdkData == null) {
                fail("Couldn't find SDK manager");
            } else {
                System.out.println("getTestSdkPath= " + TestUtils.getSdk());
                System.out.println("getPlatformDir=" + TestUtils.getLatestAndroidPlatform());
                String location = sdkData.getLocation().getPath();
                System.out.println("Using SDK at " + location);
                VersionCheck.VersionCheckResult result = VersionCheck.checkVersion(location);
                System.out.println("Version check=" + result.getRevision());
                File file = new File(location);
                if (!file.exists()) {
                    System.out.println("SDK doesn't exist");
                } else {
                    File folder = new File(location, FD_TOOLS + File.separator + FD_TEMPLATES);
                    boolean exists = folder.exists();
                    System.out.println("Template folder exists=" + exists + " for " + folder);
                }
            }
        }
    }
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) VersionCheck(com.android.tools.idea.sdk.VersionCheck)

Example 23 with AndroidSdkData

use of org.jetbrains.android.sdk.AndroidSdkData 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 24 with AndroidSdkData

use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.

the class SdksCleanupStep method cleanUpSdk.

public void cleanUpSdk(@NotNull Module module, @NotNull Collection<Sdk> invalidAndroidSdks) {
    AndroidFacet androidFacet = AndroidFacet.getInstance(module);
    if (androidFacet == null || androidFacet.getAndroidModel() == null) {
        return;
    }
    Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk != null && !invalidAndroidSdks.contains(sdk) && (isMissingAndroidLibrary(sdk) || shouldRemoveAnnotationsJar(sdk))) {
        // First try to recreate SDK; workaround for issue 78072
        AndroidSdkAdditionalData additionalData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
        AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
        if (additionalData != null && sdkData != null) {
            IAndroidTarget target = additionalData.getBuildTarget(sdkData);
            if (target == null) {
                AndroidSdkHandler sdkHandler = sdkData.getSdkHandler();
                StudioLoggerProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
                sdkHandler.getSdkManager(logger).loadSynchronously(0, logger, null, null);
                target = sdkHandler.getAndroidTargetManager(logger).getTargetFromHashString(additionalData.getBuildTargetHashString(), logger);
            }
            if (target != null) {
                SdkModificator sdkModificator = sdk.getSdkModificator();
                sdkModificator.removeAllRoots();
                for (OrderRoot orderRoot : myAndroidSdks.getLibraryRootsForTarget(target, sdk, true)) {
                    sdkModificator.addRoot(orderRoot.getFile(), orderRoot.getType());
                }
                attachJdkAnnotations(sdkModificator);
                sdkModificator.commitChanges();
            }
        }
        // above workaround deals with)
        if (isMissingAndroidLibrary(sdk)) {
            invalidAndroidSdks.add(sdk);
        }
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Sdk(com.intellij.openapi.projectRoots.Sdk) IAndroidTarget(com.android.sdklib.IAndroidTarget) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 25 with AndroidSdkData

use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.

the class AndroidLintOldTargetApiInspection method getHighestApi.

private static int getHighestApi(PsiElement element) {
    int max = SdkVersionInfo.HIGHEST_KNOWN_STABLE_API;
    AndroidFacet instance = AndroidFacet.getInstance(element);
    if (instance != null) {
        AndroidSdkData sdkData = instance.getSdkData();
        if (sdkData != null) {
            for (IAndroidTarget target : sdkData.getTargets()) {
                if (target.isPlatform()) {
                    AndroidVersion version = target.getVersion();
                    if (version.getApiLevel() > max && !version.isPreview()) {
                        max = version.getApiLevel();
                    }
                }
            }
        }
    }
    return max;
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Aggregations

AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)39 IAndroidTarget (com.android.sdklib.IAndroidTarget)15 File (java.io.File)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Sdk (com.intellij.openapi.projectRoots.Sdk)9 NotNull (org.jetbrains.annotations.NotNull)7 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)6 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)6 Nullable (org.jetbrains.annotations.Nullable)6 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)5 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)5 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AndroidVersion (com.android.sdklib.AndroidVersion)3 NewProjectWizardState (com.android.tools.idea.npw.NewProjectWizardState)3 SdkPaths.validateAndroidSdk (com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk)3 TemplateWizardState (com.android.tools.idea.wizard.template.TemplateWizardState)3 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)3 ProgressIndicator (com.android.repository.api.ProgressIndicator)2