use of com.android.tools.idea.sdk.IdeSdks in project android by JetBrains.
the class GradleSyncTest method sdkSwitch.
// Verifies that the IDE switches SDKs if the IDE and project SDKs are not the same.
@Test
public void sdkSwitch() throws IOException {
File secondSdkPath = getFilePathPropertyOrSkipTest("second.android.sdk.path", "the path of a secondary Android SDK", true);
getGuiTestSuiteState().setSkipSdkMerge(true);
IdeSdks ideSdks = IdeSdks.getInstance();
File originalSdkPath = ideSdks.getAndroidSdkPath();
guiTest.importSimpleApplication();
IdeFrameFixture ideFrame = guiTest.ideFrame();
// Change the SDK in the project. We expect the IDE to have the same SDK as the project.
LocalProperties localProperties = new LocalProperties(ideFrame.getProject());
localProperties.setAndroidSdkPath(secondSdkPath);
localProperties.save();
ideFrame.requestProjectSync();
MessagesFixture messages = ideFrame.findMessageDialog(ANDROID_SDK_MANAGER_DIALOG_TITLE);
messages.click("Use Project's SDK");
ideFrame.waitForGradleProjectSyncToFinish();
assertThat(ideSdks.getAndroidSdkPath()).isEqualTo(secondSdkPath);
// Set the project's SDK to be the original one. Now we will choose the IDE's SDK.
localProperties = new LocalProperties(ideFrame.getProject());
localProperties.setAndroidSdkPath(originalSdkPath);
localProperties.save();
ideFrame.requestProjectSync();
messages = ideFrame.findMessageDialog(ANDROID_SDK_MANAGER_DIALOG_TITLE);
messages.click("Use Android Studio's SDK");
ideFrame.waitForGradleProjectSyncToFinish();
localProperties = new LocalProperties(ideFrame.getProject());
assertThat(localProperties.getAndroidSdkPath()).isEqualTo(secondSdkPath);
}
use of com.android.tools.idea.sdk.IdeSdks 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 com.android.tools.idea.sdk.IdeSdks in project android by JetBrains.
the class AndroidSdkDataTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
File sdkDir = TestUtils.getSdk();
sdkData = AndroidSdkData.getSdkData(sdkDir);
ApplicationManager.getApplication().runWriteAction(() -> {
IdeSdks ideSdks = IdeSdks.getInstance();
ideSdks.setAndroidSdkPath(sdkDir, null);
ProjectRootManager.getInstance(getProject()).setProjectSdk(ideSdks.getEligibleAndroidSdks().get(0));
});
}
use of com.android.tools.idea.sdk.IdeSdks in project android by JetBrains.
the class AndroidGradleTestCase method setUpSdks.
private void setUpSdks() {
// We seem to have two different locations where the SDK needs to be specified.
// One is whatever is already defined in the JDK Table, and the other is the global one as defined by IdeSdks.
// Gradle import will fail if the global one isn't set.
File androidSdkPath = getSdk();
IdeSdks ideSdks = IdeSdks.getInstance();
runWriteCommandAction(getProject(), () -> {
if (IdeInfo.getInstance().isAndroidStudio()) {
ideSdks.setUseEmbeddedJdk();
LOG.info("Set JDK to " + ideSdks.getJdkPath());
}
ideSdks.setAndroidSdkPath(androidSdkPath, getProject());
LOG.info("Set IDE Sdk Path to " + androidSdkPath);
});
Sdk currentJdk = ideSdks.getJdk();
assertNotNull(currentJdk);
assertTrue("JDK 8 is required. Found: " + currentJdk.getHomePath(), Jdks.getInstance().isApplicableJdk(currentJdk, JDK_1_8));
}
use of com.android.tools.idea.sdk.IdeSdks in project android by JetBrains.
the class AndroidSdkInitializer method run.
@Override
public void run() {
if (!isAndroidSdkManagerEnabled()) {
return;
}
// If running in a GUI test we don't want the "Select SDK" dialog to show up when running GUI tests.
if (isGuiTestingMode()) {
// This is good enough. Later on in the GUI test we'll validate the given SDK path.
return;
}
IdeSdks ideSdks = IdeSdks.getInstance();
File androidSdkPath = ideSdks.getAndroidSdkPath();
if (androidSdkPath == null) {
try {
// Setup JDK and Android SDK if necessary
setUpSdks();
androidSdkPath = ideSdks.getAndroidSdkPath();
} catch (Exception e) {
LOG.error("Unexpected error while setting up SDKs: ", e);
}
}
if (androidSdkPath != null) {
AndroidSdkHandler handler = AndroidSdkHandler.getInstance(androidSdkPath);
new PatchInstallingRestarter(handler, FileOpUtils.create()).restartAndInstallIfNecessary();
// We need to start the system info monitoring even in case when user never
// runs a single emulator instance: e.g., incompatible hypervisor might be
// the reason why emulator is never run, and that's exactly the data
// SystemInfoStatsMonitor collects
new SystemInfoStatsMonitor().start();
}
}
Aggregations