use of com.android.sdklib.IAndroidTarget 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;
}
use of com.android.sdklib.IAndroidTarget 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 com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class IdeSdks method doesIdeAndroidSdkExist.
/**
* @return {@code true} if an IntelliJ SDK with the default naming convention already exists for the given Android build target.
*/
private boolean doesIdeAndroidSdkExist(@NotNull IAndroidTarget target) {
for (Sdk sdk : getEligibleAndroidSdks()) {
IAndroidTarget platformTarget = getTarget(sdk);
AndroidVersion version = target.getVersion();
AndroidVersion existingVersion = platformTarget.getVersion();
if (existingVersion.equals(version)) {
return true;
}
}
return false;
}
use of com.android.sdklib.IAndroidTarget 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 com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidSdks method chooseNameForNewLibrary.
@NotNull
public String chooseNameForNewLibrary(@NotNull IAndroidTarget target) {
if (target.isPlatform()) {
return SDK_NAME_PREFIX + target.getVersion().toString() + " Platform";
}
IAndroidTarget parentTarget = target.getParent();
String name = SDK_NAME_PREFIX;
if (parentTarget != null) {
name = name + parentTarget.getVersionName() + ' ';
}
return name + target.getName();
}
Aggregations