use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class SdksCleanupStep method reinstallMissingPlatforms.
private void reinstallMissingPlatforms(@NotNull Collection<Sdk> invalidAndroidSdks, @NotNull Project project) {
List<AndroidVersion> versionsToInstall = Lists.newArrayList();
List<String> missingPlatforms = Lists.newArrayList();
for (Sdk sdk : invalidAndroidSdks) {
AndroidSdkAdditionalData additionalData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
if (additionalData != null) {
String platform = additionalData.getBuildTargetHashString();
if (platform != null) {
missingPlatforms.add("'" + platform + "'");
AndroidVersion version = AndroidTargetHash.getPlatformVersion(platform);
if (version != null) {
versionsToInstall.add(version);
}
}
}
}
if (!versionsToInstall.isEmpty()) {
String text = "Missing Android platform(s) detected: " + Joiner.on(", ").join(missingPlatforms);
SyncMessage msg = new SyncMessage(SyncMessage.DEFAULT_GROUP, ERROR, text);
msg.add(new InstallPlatformHyperlink(versionsToInstall));
SyncMessages.getInstance(project).report(msg);
}
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class SdksCleanupStep method shouldRemoveAnnotationsJar.
/*
* Indicates whether annotations.jar should be removed from the given SDK (if it is an Android SDK.)
* There are 2 issues:
* 1. annotations.jar is not needed for API level 16 and above. The annotations are already included in android.jar. Until recently, the
* IDE added annotations.jar to the IDEA Android SDK definition unconditionally.
* 2. Because annotations.jar is in the classpath, the IDE locks the file on Windows making automatic updates of SDK Tools fail. The
* update not only fails, it corrupts the 'tools' folder in the SDK.
* From now on, creating IDEA Android SDKs will not include annotations.jar if API level is 16 or above, but we still need to remove
* this jar from existing IDEA Android SDKs.
*/
private boolean shouldRemoveAnnotationsJar(@NotNull Sdk sdk) {
if (myAndroidSdks.isAndroidSdk(sdk)) {
AndroidSdkAdditionalData additionalData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
boolean needsAnnotationsJar = false;
if (additionalData != null && sdkData != null) {
IAndroidTarget target = additionalData.getBuildTarget(sdkData);
if (target != null) {
needsAnnotationsJar = myAndroidSdks.needsAnnotationsJarInClasspath(target);
}
}
for (VirtualFile library : sdk.getRootProvider().getFiles(CLASSES)) {
// annotations.jar and res folder.
if (library.getName().equals(FN_ANNOTATIONS_JAR) && library.exists() && !needsAnnotationsJar) {
return true;
}
}
}
return false;
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class GradleSpecificInitializer method setupSdks.
private static void setupSdks() {
IdeSdks ideSdks = IdeSdks.getInstance();
File androidHome = ideSdks.getAndroidSdkPath();
if (androidHome != null) {
String androidHomePath = androidHome.getAbsolutePath();
ValidationResult result = validateLocation(androidHomePath, "Android SDK location", false, WritableCheckMode.DO_NOT_CHECK);
if (result.isError()) {
notifyInvalidSdk();
}
// Do not prompt user to select SDK path (we have one already.) Instead, check SDK compatibility when a project is opened.
return;
}
// If running in a GUI test we don't want the "Select SDK" dialog to show up when running GUI tests.
if (AndroidPlugin.isGuiTestingMode()) {
// This is good enough. Later on in the GUI test we'll validate the given SDK path.
return;
}
Sdk sdk = findFirstCompatibleAndroidSdk();
if (sdk != null) {
String sdkHomePath = sdk.getHomePath();
assert sdkHomePath != null;
ideSdks.createAndroidSdkPerAndroidTarget(new File(toSystemDependentName(sdkHomePath)));
return;
}
// Called in a 'invokeLater' block, otherwise file chooser will hang forever.
ApplicationManager.getApplication().invokeLater(() -> {
File androidSdkPath = getAndroidSdkPath();
if (androidSdkPath == null) {
return;
}
FirstRunWizardMode wizardMode = AndroidStudioWelcomeScreenProvider.getWizardMode();
// Only show "Select SDK" dialog if the "First Run" wizard is not displayed.
boolean promptSdkSelection = wizardMode == null;
Sdk sdk1 = createNewAndroidPlatform(androidSdkPath.getPath(), promptSdkSelection);
if (sdk1 != null) {
// Rename the SDK to fit our default naming convention.
String sdkNamePrefix = AndroidSdks.SDK_NAME_PREFIX;
if (sdk1.getName().startsWith(sdkNamePrefix)) {
SdkModificator sdkModificator = sdk1.getSdkModificator();
sdkModificator.setName(sdkNamePrefix + sdk1.getName().substring(sdkNamePrefix.length()));
sdkModificator.commitChanges();
// Rename the JDK that goes along with this SDK.
AndroidSdkAdditionalData additionalData = AndroidSdks.getInstance().getAndroidSdkAdditionalData(sdk1);
if (additionalData != null) {
Sdk jdk = additionalData.getJavaSdk();
if (jdk != null) {
sdkModificator = jdk.getSdkModificator();
sdkModificator.setName(DEFAULT_JDK_NAME);
sdkModificator.commitChanges();
}
}
// Fill out any missing build APIs for this new SDK.
ideSdks.createAndroidSdkPerAndroidTarget(androidSdkPath);
}
}
});
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class AndroidSdksTest method getAndroidSdkAdditionalData.
@NotNull
private AndroidSdkAdditionalData getAndroidSdkAdditionalData(@NotNull Sdk sdk) {
// Indirectly tests AndroidSdks#getAndroidSdkAdditionalData
AndroidSdkAdditionalData data = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
assertNotNull(data);
return data;
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class AndroidSdksTest method testFindSuitableAndroidSdk.
public void testFindSuitableAndroidSdk() {
IAndroidTarget target = findAndroidTarget();
Sdk sdk = myAndroidSdks.create(target, mySdkPath, myJdk, false);
assertNotNull(sdk);
String hash = getTargetHashString(target);
Sdk foundSdk = myAndroidSdks.findSuitableAndroidSdk(hash);
assertNotNull(foundSdk);
assertEquals(sdk.getHomePath(), foundSdk.getHomePath());
AndroidSdkAdditionalData data = getAndroidSdkAdditionalData(foundSdk);
assertEquals(hash, data.getBuildTargetHashString());
}
Aggregations