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 AndroidSdkInitializer method setUpSdks.
private static void setUpSdks() {
Sdk sdk = findFirstCompatibleAndroidSdk();
if (sdk != null) {
String sdkHomePath = sdk.getHomePath();
assert sdkHomePath != null;
IdeSdks.getInstance().createAndroidSdkPerAndroidTarget(new File(toSystemDependentName(sdkHomePath)));
return;
}
// Called in a 'invokeLater' block, otherwise file chooser will hang forever.
ApplicationManager.getApplication().invokeLater(() -> {
File androidSdkPath = findOrGetAndroidSdkPath();
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 newSdk = createNewAndroidPlatform(androidSdkPath.getPath(), promptSdkSelection);
if (newSdk != null) {
// Rename the SDK to fit our default naming convention.
String sdkNamePrefix = AndroidSdks.SDK_NAME_PREFIX;
if (newSdk.getName().startsWith(sdkNamePrefix)) {
SdkModificator sdkModificator = newSdk.getSdkModificator();
sdkModificator.setName(sdkNamePrefix + newSdk.getName().substring(sdkNamePrefix.length()));
sdkModificator.commitChanges();
// Rename the JDK that goes along with this SDK.
AndroidSdkAdditionalData additionalData = AndroidSdks.getInstance().getAndroidSdkAdditionalData(newSdk);
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.getInstance().createAndroidSdkPerAndroidTarget(androidSdkPath);
}
}
});
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class AndroidFacetImporterBase method createNewAndroidSdkForMaven.
@Nullable
private static Sdk createNewAndroidSdkForMaven(File sdkPath, IAndroidTarget target) {
AndroidSdks androidSdks = AndroidSdks.getInstance();
Sdk sdk = null;
Sdk jdk = Jdks.getInstance().chooseOrCreateJavaSdk();
if (jdk != null) {
String sdkName = "Maven " + androidSdks.chooseNameForNewLibrary(target);
sdk = androidSdks.create(target, sdkPath, sdkName, jdk, false);
}
if (sdk == null) {
return null;
}
SdkModificator modificator = sdk.getSdkModificator();
for (OrderRoot root : androidSdks.getLibraryRootsForTarget(target, sdkPath, false)) {
modificator.addRoot(root.getFile(), root.getType());
}
AndroidSdkAdditionalData data = androidSdks.getAndroidSdkAdditionalData(sdk);
if (data != null) {
final Sdk javaSdk = data.getJavaSdk();
if (javaSdk != null) {
for (VirtualFile file : javaSdk.getRootProvider().getFiles(OrderRootType.CLASSES)) {
modificator.addRoot(file, OrderRootType.CLASSES);
}
} else {
LOG.error("AndroidSdkUtils.createNewAndroidPlatform should return Android SDK with a valid JDK reference, or return null");
}
}
modificator.commitChanges();
return sdk;
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class SdksCleanupStep method cleanUpSdk.
public void cleanUpSdk(@NotNull Module module, @NotNull Collection<Sdk> invalidAndroidSdks) {
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
if (androidFacet == null || androidFacet.getAndroidModel() == null) {
return;
}
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk != null && !invalidAndroidSdks.contains(sdk) && (isMissingAndroidLibrary(sdk) || shouldRemoveAnnotationsJar(sdk))) {
// First try to recreate SDK; workaround for issue 78072
AndroidSdkAdditionalData additionalData = myAndroidSdks.getAndroidSdkAdditionalData(sdk);
AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
if (additionalData != null && sdkData != null) {
IAndroidTarget target = additionalData.getBuildTarget(sdkData);
if (target == null) {
AndroidSdkHandler sdkHandler = sdkData.getSdkHandler();
StudioLoggerProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
sdkHandler.getSdkManager(logger).loadSynchronously(0, logger, null, null);
target = sdkHandler.getAndroidTargetManager(logger).getTargetFromHashString(additionalData.getBuildTargetHashString(), logger);
}
if (target != null) {
SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.removeAllRoots();
for (OrderRoot orderRoot : myAndroidSdks.getLibraryRootsForTarget(target, sdk, true)) {
sdkModificator.addRoot(orderRoot.getFile(), orderRoot.getType());
}
attachJdkAnnotations(sdkModificator);
sdkModificator.commitChanges();
}
}
// above workaround deals with)
if (isMissingAndroidLibrary(sdk)) {
invalidAndroidSdks.add(sdk);
}
}
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class RenderErrorContributor method isBuiltByJdk7OrHigher.
static boolean isBuiltByJdk7OrHigher(@NotNull Module module) {
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk == null) {
return false;
}
AndroidSdks androidSdks = AndroidSdks.getInstance();
if (androidSdks.isAndroidSdk(sdk)) {
AndroidSdkAdditionalData data = androidSdks.getAndroidSdkAdditionalData(sdk);
if (data != null) {
Sdk jdk = data.getJavaSdk();
if (jdk != null) {
sdk = jdk;
}
}
}
return sdk.getSdkType() instanceof JavaSdk && JavaSdk.getInstance().isOfVersionOrHigher(sdk, JavaSdkVersion.JDK_1_7);
}
Aggregations