use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class ProjectResourceIdResolver method getIdMap.
private TIntObjectHashMap<String> getIdMap() {
AndroidFacet facet = null;
for (Module m : ModuleManager.getInstance(myProject).getModules()) {
facet = AndroidFacet.getInstance(m);
if (facet != null) {
break;
}
}
AndroidSdkData sdkData = facet == null ? null : facet.getSdkData();
if (sdkData == null) {
return null;
}
IAndroidTarget[] targets = sdkData.getTargets();
if (targets.length == 0) {
return null;
}
return sdkData.getTargetData(targets[targets.length - 1]).getPublicIdMap();
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class DependenciesModuleSetupStep method addExtraSdkLibrariesAsDependencies.
/**
* Sets the 'useLibrary' libraries or SDK add-ons as library dependencies.
* <p>
* These libraries are set at the project level, which makes it impossible to add them to a IDE SDK definition because the IDE SDK is
* global to the whole IDE. To work around this limitation, we set these libraries as module dependencies instead.
* </p>
*/
private void addExtraSdkLibrariesAsDependencies(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull AndroidProject androidProject) {
ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
Sdk sdk = moduleModel.getSdk();
// If we got here, SDK will *NOT* be null.
assert sdk != null;
String suffix = null;
AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
if (sdkData != null) {
SdkAdditionalData data = sdk.getSdkAdditionalData();
if (data instanceof AndroidSdkAdditionalData) {
AndroidSdkAdditionalData androidSdkData = (AndroidSdkAdditionalData) data;
suffix = androidSdkData.getBuildTargetHashString();
}
}
if (suffix == null) {
// In practice, we won't get here. A proper Android SDK has been already configured by now, and the suffix won't be null.
suffix = androidProject.getCompileTarget();
}
Set<String> currentIdeSdkFilePaths = Sets.newHashSetWithExpectedSize(5);
for (VirtualFile sdkFile : sdk.getRootProvider().getFiles(CLASSES)) {
// We need to convert the VirtualFile to java.io.File, because the path of the VirtualPath is using 'jar' protocol and it won't match
// the path returned by AndroidProject#getBootClasspath().
File sdkFilePath = virtualToIoFile(sdkFile);
currentIdeSdkFilePaths.add(sdkFilePath.getPath());
}
Collection<String> bootClasspath = androidProject.getBootClasspath();
for (String library : bootClasspath) {
if (isNotEmpty(library) && !currentIdeSdkFilePaths.contains(library)) {
// Library is not in the SDK IDE definition. Add it as library and make the module depend on it.
File binaryPath = new File(library);
String name = binaryPath.isFile() ? getNameWithoutExtension(binaryPath) : sanitizeFileName(library);
// Include compile target as part of the name, to ensure the library name is unique to this Android platform.
// e.g. maps-android-23, effects-android-23 (it follows the library naming convention: library-version
name = name + "-" + suffix;
myDependenciesSetup.setUpLibraryDependency(module, modelsProvider, name, COMPILE, binaryPath);
}
}
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class FormFactorApiComboBox method deriveValues.
/**
* Fill in the values that can be derived from the selected min SDK level:
*
* minApiLevel will be set to the selected api level (string or number)
* minApi will be set to the numerical equivalent
* buildApi will be set to the highest installed platform, or to the preview platform if a preview is selected
* buildApiString will be set to the corresponding string
* targetApi will be set to the highest installed platform or to the preview platform if a preview is selected
* targetApiString will be set to the corresponding string
*
* @param stateStore
* @param modified
*/
public void deriveValues(@NotNull ScopedStateStore stateStore, @NotNull Set<Key> modified) {
if (modified.contains(myTargetComboBoxKey) || modified.contains(myInclusionKey)) {
// First remove the last request, no need to install more than one platform
if (!myInstallRequests.isEmpty()) {
for (String request : myInstallRequests) {
stateStore.listRemove(INSTALL_REQUESTS_KEY, request);
}
myInstallRequests.clear();
}
// If this form factor is not included then there is nothing to do:
AndroidTargetComboBoxItem targetItem = stateStore.get(myTargetComboBoxKey);
if (targetItem == null || !stateStore.getNotNull(myInclusionKey, false)) {
return;
}
stateStore.put(FormFactorUtils.getMinApiKey(myFormFactor), targetItem.getData());
stateStore.put(FormFactorUtils.getMinApiLevelKey(myFormFactor), targetItem.myApiLevel);
IAndroidTarget target = targetItem.target;
if (target != null && (target.getVersion().isPreview() || !target.isPlatform())) {
// Make sure we set target and build to the preview version as well
populateApiLevels(targetItem.myApiLevel, target, stateStore);
} else {
int targetApiLevel;
if (ourHighestInstalledApiTarget != null) {
targetApiLevel = ourHighestInstalledApiTarget.getVersion().getFeatureLevel();
} else {
targetApiLevel = 0;
}
populateApiLevels(targetApiLevel, ourHighestInstalledApiTarget, stateStore);
}
AndroidVersion androidVersion = targetItem.myAndroidVersion;
String platformPath = DetailsTypes.getPlatformPath(androidVersion);
// Update build tools: use preview versions with preview platforms, etc
BuildToolInfo buildTool = (target == null) ? null : target.getBuildToolInfo();
if (buildTool == null) {
final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
buildTool = sdkHandler.getLatestBuildTool(new StudioLoggerProgressIndicator(ConfigureAndroidProjectPath.class), false);
}
if (buildTool != null) {
stateStore.put(WizardConstants.BUILD_TOOLS_VERSION_KEY, buildTool.getRevision().toString());
}
// Check to see if this is installed. If not, request that we install it
if (targetItem.myAddon != null) {
// The user selected a non platform SDK (e.g. for Google Glass). Let us install it:
String packagePath = targetItem.myAddon.getPath();
stateStore.listPush(INSTALL_REQUESTS_KEY, packagePath);
myInstallRequests.add(packagePath);
// We also need the platform if not already installed:
AndroidTargetManager targetManager = AndroidSdks.getInstance().tryToChooseSdkHandler().getAndroidTargetManager(REPO_LOG);
if (targetManager.getTargetFromHashString(AndroidTargetHash.getPlatformHashString(androidVersion), REPO_LOG) == null) {
stateStore.listPush(INSTALL_REQUESTS_KEY, platformPath);
myInstallRequests.add(platformPath);
}
// The selected minVersion should also be the buildApi:
populateApiLevels(targetItem.myApiLevel, null, stateStore);
} else if (target == null) {
// unlikely, so this logic can wait for a followup CL.
if (ourHighestInstalledApiTarget == null || (androidVersion.getApiLevel() > ourHighestInstalledApiTarget.getVersion().getApiLevel() && !ourInstalledVersions.contains(androidVersion))) {
// Let us install the HIGHEST_KNOWN_STABLE_API.
platformPath = DetailsTypes.getPlatformPath(new AndroidVersion(SdkVersionInfo.HIGHEST_KNOWN_STABLE_API, null));
stateStore.listPush(INSTALL_REQUESTS_KEY, platformPath);
myInstallRequests.add(platformPath);
// HIGHEST_KNOWN_STABLE_API would also be the highest sdkVersion after this install, so specify buildApi again here:
populateApiLevels(SdkVersionInfo.HIGHEST_KNOWN_STABLE_API, null, stateStore);
}
}
PropertiesComponent.getInstance().setValue(getPropertiesComponentMinSdkKey(myFormFactor), targetItem.getData());
// Check Java language level; should be 7 for L; eventually this will be automatically defaulted by the Android Gradle plugin
// instead: https://code.google.com/p/android/issues/detail?id=76252
String javaVersion = null;
if (ourHighestInstalledApiTarget != null && ourHighestInstalledApiTarget.getVersion().getFeatureLevel() >= 21) {
AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (sdkData != null) {
JavaSdk jdk = JavaSdk.getInstance();
Sdk sdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(jdk);
if (sdk != null) {
JavaSdkVersion version = jdk.getVersion(sdk);
if (version != null && version.isAtLeast(JavaSdkVersion.JDK_1_7)) {
javaVersion = JavaSdkVersion.JDK_1_7.getDescription();
}
}
}
}
stateStore.put(FormFactorUtils.getLanguageLevelKey(myFormFactor), javaVersion);
}
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class NewProjectWizardDynamic method initState.
static void initState(@NotNull ScopedStateStore state, @NotNull String gradlePluginVersion) {
state.put(GRADLE_PLUGIN_VERSION_KEY, gradlePluginVersion);
state.put(GRADLE_VERSION_KEY, SdkConstants.GRADLE_LATEST_VERSION);
state.put(IS_GRADLE_PROJECT_KEY, true);
state.put(IS_NEW_PROJECT_KEY, true);
state.put(TARGET_FILES_KEY, new HashSet<>());
state.put(FILES_TO_OPEN_KEY, new ArrayList<>());
state.put(USE_PER_MODULE_REPOS_KEY, false);
state.put(ALSO_CREATE_IAPK_KEY, true);
// For now, our definition of low memory is running in a 32-bit JVM. In this case, we have to be careful about the amount of memory we
// request for the Gradle build.
state.put(WizardConstants.IS_LOW_MEMORY_KEY, SystemInfo.is32Bit);
try {
state.put(DEBUG_KEYSTORE_SHA_1_KEY, KeystoreUtils.sha1(KeystoreUtils.getOrCreateDefaultDebugKeystore()));
} catch (Exception exception) {
LOG.warn("Could not create debug keystore", exception);
state.put(DEBUG_KEYSTORE_SHA_1_KEY, "");
}
String mavenUrl = System.getProperty(TemplateWizard.MAVEN_URL_PROPERTY);
if (mavenUrl != null) {
state.put(MAVEN_URL_KEY, mavenUrl);
}
AndroidSdkData data = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (data != null) {
File sdkLocation = data.getLocation();
state.put(SDK_DIR_KEY, sdkLocation.getPath());
String espressoVersion = RepositoryUrlManager.get().getLibraryRevision(SupportLibrary.ESPRESSO_CORE.getGroupId(), SupportLibrary.ESPRESSO_CORE.getArtifactId(), null, false, sdkLocation, FileOpUtils.create());
if (espressoVersion != null) {
state.put(ESPRESSO_VERSION_KEY, espressoVersion);
}
}
}
use of org.jetbrains.android.sdk.AndroidSdkData in project android by JetBrains.
the class TemplateWizard method getSdk.
@Nullable
protected static Sdk getSdk(int apiLevel) {
for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) {
AndroidPlatform androidPlatform = AndroidPlatform.parse(sdk);
if (androidPlatform != null) {
AndroidSdkData sdkData = androidPlatform.getSdkData();
IAndroidTarget target = sdkData.findTargetByApiLevel(Integer.toString(apiLevel));
if (target != null) {
return sdk;
}
}
}
return null;
}
Aggregations