Search in sources :

Example 6 with AndroidSdks

use of com.android.tools.idea.sdk.AndroidSdks in project android by JetBrains.

the class AndroidFacetImporterBase method createNewAndroidSdkForMaven.

@Nullable
private static Sdk createNewAndroidSdkForMaven(File sdkPath, IAndroidTarget target) {
    AndroidSdks androidSdks = AndroidSdks.getInstance();
    Sdk sdk = null;
    Sdk jdk = Jdks.getInstance().chooseOrCreateJavaSdk();
    if (jdk != null) {
        String sdkName = "Maven " + androidSdks.chooseNameForNewLibrary(target);
        sdk = androidSdks.create(target, sdkPath, sdkName, jdk, false);
    }
    if (sdk == null) {
        return null;
    }
    SdkModificator modificator = sdk.getSdkModificator();
    for (OrderRoot root : androidSdks.getLibraryRootsForTarget(target, sdkPath, false)) {
        modificator.addRoot(root.getFile(), root.getType());
    }
    AndroidSdkAdditionalData data = androidSdks.getAndroidSdkAdditionalData(sdk);
    if (data != null) {
        final Sdk javaSdk = data.getJavaSdk();
        if (javaSdk != null) {
            for (VirtualFile file : javaSdk.getRootProvider().getFiles(OrderRootType.CLASSES)) {
                modificator.addRoot(file, OrderRootType.CLASSES);
            }
        } else {
            LOG.error("AndroidSdkUtils.createNewAndroidPlatform should return Android SDK with a valid JDK reference, or return null");
        }
    }
    modificator.commitChanges();
    return sdk;
}
Also used : AndroidSdks(com.android.tools.idea.sdk.AndroidSdks) AndroidSdkAdditionalData(org.jetbrains.android.sdk.AndroidSdkAdditionalData) OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AndroidSdks (com.android.tools.idea.sdk.AndroidSdks)6 Sdk (com.intellij.openapi.projectRoots.Sdk)5 ModuleRootModificationUtil.setModuleSdk (com.intellij.openapi.roots.ModuleRootModificationUtil.setModuleSdk)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)2 Nullable (org.jetbrains.annotations.Nullable)2 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 ArchiveFileType (com.intellij.ide.highlighter.ArchiveFileType)1 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)1 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)1