use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class IdeSdksConfigurable method getFirstDefaultAndroidSdk.
/**
* Returns the first SDK it finds that matches our default naming convention. There will be several SDKs so named, one for each build
* target installed in the SDK; which of those this method returns is not defined.
*
* @param create True if this method should attempt to create an SDK if one does not exist.
* @return null if an SDK is unavailable or creation failed.
*/
@Nullable
private static Sdk getFirstDefaultAndroidSdk(boolean create) {
IdeSdks ideSdks = IdeSdks.getInstance();
List<Sdk> allAndroidSdks = ideSdks.getEligibleAndroidSdks();
if (!allAndroidSdks.isEmpty()) {
return allAndroidSdks.get(0);
}
if (!create) {
return null;
}
AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (sdkData == null) {
return null;
}
List<Sdk> sdks = ideSdks.createAndroidSdkPerAndroidTarget(sdkData.getLocation());
return !sdks.isEmpty() ? sdks.get(0) : null;
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class GradleSyncTest method sdkCreationForAddons.
// https://code.google.com/p/android/issues/detail?id=185313
@Test
public void sdkCreationForAddons() throws IOException {
guiTest.importSimpleApplication();
IdeFrameFixture ideFrame = guiTest.ideFrame();
Project project = ideFrame.getProject();
Module appModule = ideFrame.getModule("app");
GradleBuildFile buildFile = GradleBuildFile.get(appModule);
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
runWriteCommandAction(project, () -> buildFile.setValue(BuildFileKey.COMPILE_SDK_VERSION, "Google Inc.:Google APIs:24"));
}
});
ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
Sdk sdk = ModuleRootManager.getInstance(appModule).getSdk();
AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
SdkAdditionalData data = sdk.getSdkAdditionalData();
assertThat(data).isInstanceOf(AndroidSdkAdditionalData.class);
AndroidSdkAdditionalData androidSdkData = (AndroidSdkAdditionalData) data;
IAndroidTarget buildTarget = androidSdkData.getBuildTarget(sdkData);
// By checking that there are no additional libraries in the SDK, we are verifying that an additional SDK was not created for add-ons.
assertThat(buildTarget.getAdditionalLibraries()).hasSize(0);
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class AdtImportBuilder method createImporter.
protected GradleImport createImporter(@NotNull List<File> projects) {
GradleImport importer = new GradleImport();
importer.setImportIntoExisting(!myCreateProject);
if (myCreateProject) {
File templates = TemplateManager.getTemplateRootFolder();
if (templates != null) {
File wrapper = TemplateManager.getWrapperLocation(templates);
if (wrapper.exists()) {
importer.setGradleWrapperLocation(wrapper);
AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (sdkData != null) {
importer.setSdkLocation(sdkData.getLocation());
}
}
}
}
try {
importer.importProjects(projects);
} catch (IOException ioe) {
// pass: the errors are written into the import error list shown in the warnings panel
}
return importer;
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class GradleFilePsiMerger method mergeDependencies.
private static void mergeDependencies(@NotNull PsiElement fromRoot, @NotNull PsiElement toRoot, @NotNull Project project, @Nullable String supportLibVersionFilter) {
Map<String, Multimap<String, GradleCoordinate>> dependencies = Maps.newHashMap();
final List<String> unparsedDependencies = Lists.newArrayList();
// Load existing dependencies into the map for the existing build.gradle
pullDependenciesIntoMap(toRoot, dependencies, null);
// Load dependencies into the map for the new build.gradle
pullDependenciesIntoMap(fromRoot, dependencies, unparsedDependencies);
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project);
RepositoryUrlManager urlManager = RepositoryUrlManager.get();
ImmutableList<String> configurations = CONFIGURATION_ORDERING.immutableSortedCopy(dependencies.keySet());
AndroidSdkData sdk = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (sdk != null) {
for (String configurationName : configurations) {
List<GradleCoordinate> resolved = urlManager.resolveDynamicSdkDependencies(dependencies.get(configurationName), supportLibVersionFilter, sdk, FileOpUtils.create());
for (GradleCoordinate dependency : resolved) {
PsiElement dependencyElement = factory.createStatementFromText(String.format("%s '%s'\n", configurationName, dependency.toString()));
toRoot.addBefore(dependencyElement, toRoot.getLastChild());
}
}
}
for (String dependency : unparsedDependencies) {
PsiElement dependencyElement = factory.createStatementFromText(dependency);
toRoot.addBefore(dependencyElement, toRoot.getLastChild());
}
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class TemplateManager method getTemplateRootFolder.
/**
* @return the root folder containing templates
*/
@Nullable
public static File getTemplateRootFolder() {
String homePath = toSystemIndependentName(PathManager.getHomePath());
// Release build?
VirtualFile root = LocalFileSystem.getInstance().findFileByPath(toSystemIndependentName(homePath + BUNDLED_TEMPLATE_PATH));
if (root == null) {
// Development build?
for (String path : DEVELOPMENT_TEMPLATE_PATHS) {
root = LocalFileSystem.getInstance().findFileByPath(toSystemIndependentName(homePath + path));
if (root != null) {
break;
}
}
}
if (root != null) {
File rootFile = VfsUtilCore.virtualToIoFile(root);
if (templateRootIsValid(rootFile)) {
return rootFile;
}
}
// Fall back to SDK template root
AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (sdkData != null) {
File location = sdkData.getLocation();
File folder = new File(location, FD_TOOLS + File.separator + FD_TEMPLATES);
if (folder.isDirectory()) {
return folder;
}
}
return null;
}
Aggregations