use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class IdeSdks method createAndroidSdkPerAndroidTarget.
/**
* Creates a set of IntelliJ SDKs (one for each build target) corresponding to the Android SDK in the given directory, if SDKs with the
* default naming convention and each individual build target do not already exist. If IntelliJ SDKs do exist, they are not updated.
*/
@NotNull
private List<Sdk> createAndroidSdkPerAndroidTarget(@NotNull File androidSdkPath, @Nullable Sdk javaSdk) {
AndroidSdkData sdkData = getSdkData(androidSdkPath);
if (sdkData == null) {
return Collections.emptyList();
}
IAndroidTarget[] targets = sdkData.getTargets(false);
if (targets.length == 0) {
return Collections.emptyList();
}
List<Sdk> sdks = new ArrayList<>();
Sdk ideJdk = javaSdk != null ? javaSdk : getJdk();
if (ideJdk != null) {
for (IAndroidTarget target : targets) {
if (target.isPlatform() && !doesIdeAndroidSdkExist(target)) {
String name = myAndroidSdks.chooseNameForNewLibrary(target);
Sdk sdk = myAndroidSdks.create(target, sdkData.getLocation(), name, ideJdk, true);
if (sdk != null) {
sdks.add(sdk);
}
}
}
}
return sdks;
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class IdeSdks method setAndroidSdkPath.
/**
* Sets the path of Android Studio's Android SDK. This method should be called in a write action. It is assumed that the given path has
* been validated by {@link #isValidAndroidSdkPath(File)}. This method will fail silently if the given path is not valid.
*
* @param path the path of the Android SDK.
* @see com.intellij.openapi.application.Application#runWriteAction(Runnable)
*/
@NotNull
public List<Sdk> setAndroidSdkPath(@NotNull File path, @Nullable Sdk javaSdk, @Nullable Project currentProject) {
if (isValidAndroidSdkPath(path)) {
ApplicationManager.getApplication().assertWriteAccessAllowed();
// given path as well in order to be able to fallback to it later if there is still no android sdk configured within the ide.
if (currentProject != null && !currentProject.isDisposed()) {
String sdkPath = toCanonicalPath(path.getAbsolutePath());
PropertiesComponent.getInstance(currentProject).setValue(ANDROID_SDK_PATH_KEY, sdkPath);
if (!currentProject.isDefault()) {
// Store default sdk path for default project as well in order to be able to re-use it for another ide projects if necessary.
PropertiesComponent component = PropertiesComponent.getInstance(ProjectManager.getInstance().getDefaultProject());
component.setValue(ANDROID_SDK_PATH_KEY, sdkPath);
}
}
// Since removing SDKs is *not* asynchronous, we force an update of the SDK Manager.
// If we don't force this update, AndroidSdks will still use the old SDK until all SDKs are properly deleted.
AndroidSdkData oldSdkData = getSdkData(path);
myAndroidSdks.setSdkData(oldSdkData);
// Set up a list of SDKs we don't need any more. At the end we'll delete them.
List<Sdk> sdksToDelete = new ArrayList<>();
File resolved = resolvePath(path);
// Parse out the new SDK. We'll need its targets to set up IntelliJ SDKs for each.
AndroidSdkData sdkData = getSdkData(resolved, true);
if (sdkData != null) {
// Iterate over all current existing IJ Android SDKs
for (Sdk sdk : myAndroidSdks.getAllAndroidSdks()) {
if (sdk.getName().startsWith(SDK_NAME_PREFIX)) {
sdksToDelete.add(sdk);
}
}
}
for (Sdk sdk : sdksToDelete) {
ProjectJdkTable.getInstance().removeJdk(sdk);
}
// If there are any API targets that we haven't created IntelliJ SDKs for yet, fill those in.
List<Sdk> sdks = createAndroidSdkPerAndroidTarget(resolved, javaSdk);
afterAndroidSdkPathUpdate(resolved);
return sdks;
}
return Collections.emptyList();
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class AndroidSdks method tryToCreate.
@Nullable
public Sdk tryToCreate(@NotNull File sdkPath, @NotNull String targetHashString) {
AndroidSdkData sdkData = getSdkData(sdkPath);
if (sdkData != null) {
sdkData.getSdkHandler().getSdkManager(new StudioLoggerProgressIndicator(AndroidSdks.class)).markInvalid();
IAndroidTarget target = sdkData.findTargetByHashString(targetHashString);
if (target != null) {
return create(target, sdkData.getLocation(), true);
}
}
return null;
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class RepositoryUrlManager method getLibraryStringCoordinate.
@Nullable
public String getLibraryStringCoordinate(SupportLibrary library, boolean preview) {
AndroidSdkData sdk = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (sdk == null) {
return null;
}
String revision = getLibraryRevision(library.getGroupId(), library.getArtifactId(), null, preview, sdk.getLocation(), FileOpUtils.create());
if (revision == null) {
return null;
}
return library.getGradleCoordinate(revision).toString();
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class TemplateUtils method getKnownVersions.
/**
* Returns a list of known API names
*
* @return a list of string API names, starting from 1 and up through the
* maximum known versions (with no gaps)
*/
@NotNull
public static String[] getKnownVersions() {
final AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
assert sdkData != null;
int max = SdkVersionInfo.HIGHEST_KNOWN_STABLE_API;
IAndroidTarget[] targets = sdkData.getTargets();
SparseArray<IAndroidTarget> apiTargets = null;
for (IAndroidTarget target : targets) {
if (target.isPlatform()) {
AndroidVersion version = target.getVersion();
if (!version.isPreview()) {
int apiLevel = version.getApiLevel();
max = Math.max(max, apiLevel);
if (apiLevel > SdkVersionInfo.HIGHEST_KNOWN_API) {
if (apiTargets == null) {
apiTargets = new SparseArray<IAndroidTarget>();
}
apiTargets.put(apiLevel, target);
}
}
}
}
String[] versions = new String[max];
for (int api = 1; api <= max; api++) {
String name = SdkVersionInfo.getAndroidName(api);
// noinspection ConstantConditions
if (name == null) {
if (apiTargets != null) {
IAndroidTarget target = apiTargets.get(api);
if (target != null) {
name = AndroidSdkUtils.getTargetLabel(target);
}
}
if (name == null) {
name = String.format("API %1$d", api);
}
}
versions[api - 1] = name;
}
return versions;
}
Aggregations