use of org.jetbrains.android.sdk.AndroidSdkAdditionalData 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.AndroidSdkAdditionalData in project android by JetBrains.
the class AndroidSdks method setUpSdk.
public void setUpSdk(@NotNull Sdk androidSdk, @NotNull SdkModificator androidSdkModificator, @NotNull IAndroidTarget target, @NotNull String sdkName, @NotNull Collection<Sdk> allSdks, @Nullable Sdk jdk, boolean addRoots) {
AndroidSdkAdditionalData data = new AndroidSdkAdditionalData(androidSdk, jdk);
data.setBuildTarget(target);
String name = createUniqueSdkName(sdkName, allSdks);
androidSdkModificator.setName(name);
if (jdk != null) {
androidSdkModificator.setVersionString(jdk.getVersionString());
}
androidSdkModificator.setSdkAdditionalData(data);
if (addRoots) {
List<OrderRoot> newRoots = getLibraryRootsForTarget(target, androidSdk, true);
androidSdkModificator.removeAllRoots();
for (OrderRoot orderRoot : newRoots) {
androidSdkModificator.addRoot(orderRoot.getFile(), orderRoot.getType());
}
// TODO move this method to Jdks.
attachJdkAnnotations(androidSdkModificator);
}
// Add sources at the end, otherwise if 'addRoots' is true, removing all existing roots will delete sources as well.
// https://code.google.com/p/android/issues/detail?id=233221
findAndSetPlatformSources(target, androidSdkModificator);
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class AndroidSdks method findSuitableAndroidSdk.
@Nullable
public Sdk findSuitableAndroidSdk(@NotNull String targetHash) {
Set<String> foundSdkHomePaths = new HashSet<>();
List<Sdk> notCompatibleSdks = new ArrayList<>();
for (Sdk sdk : getAllAndroidSdks()) {
AndroidSdkAdditionalData originalData = getAndroidSdkAdditionalData(sdk);
if (originalData == null) {
continue;
}
String sdkHomePath = sdk.getHomePath();
if (!foundSdkHomePaths.contains(sdkHomePath) && targetHash.equals(originalData.getBuildTargetHashString())) {
if (VersionCheck.isCompatibleVersion(sdkHomePath)) {
return sdk;
}
notCompatibleSdks.add(sdk);
if (sdkHomePath != null) {
foundSdkHomePaths.add(sdkHomePath);
}
}
}
return notCompatibleSdks.isEmpty() ? null : notCompatibleSdks.get(0);
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class GradleSyncTest method sdkCreationForAddons.
// https://code.google.com/p/android/issues/detail?id=185313
@Test
public void sdkCreationForAddons() throws IOException {
guiTest.importSimpleApplication();
IdeFrameFixture ideFrame = guiTest.ideFrame();
Project project = ideFrame.getProject();
Module appModule = ideFrame.getModule("app");
GradleBuildFile buildFile = GradleBuildFile.get(appModule);
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
runWriteCommandAction(project, () -> buildFile.setValue(BuildFileKey.COMPILE_SDK_VERSION, "Google Inc.:Google APIs:24"));
}
});
ideFrame.requestProjectSync().waitForGradleProjectSyncToFinish();
Sdk sdk = ModuleRootManager.getInstance(appModule).getSdk();
AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdk);
SdkAdditionalData data = sdk.getSdkAdditionalData();
assertThat(data).isInstanceOf(AndroidSdkAdditionalData.class);
AndroidSdkAdditionalData androidSdkData = (AndroidSdkAdditionalData) data;
IAndroidTarget buildTarget = androidSdkData.getBuildTarget(sdkData);
// By checking that there are no additional libraries in the SDK, we are verifying that an additional SDK was not created for add-ons.
assertThat(buildTarget.getAdditionalLibraries()).hasSize(0);
}
use of org.jetbrains.android.sdk.AndroidSdkAdditionalData in project android by JetBrains.
the class AndroidJunitPatcher method patchJavaParameters.
@Override
public void patchJavaParameters(@Nullable Module module, JavaParameters javaParameters) {
if (module == null) {
return;
}
AndroidModuleModel androidModel = AndroidModuleModel.get(module);
if (androidModel == null) {
return;
}
// Modify the class path only if we're dealing with the unit test artifact.
PathsList classPath = javaParameters.getClassPath();
Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
if (sdk == null || !(sdk.getSdkType() instanceof AndroidSdkType)) {
return;
}
SdkAdditionalData data = sdk.getSdkAdditionalData();
if (!(data instanceof AndroidSdkAdditionalData)) {
return;
}
AndroidPlatform platform = ((AndroidSdkAdditionalData) data).getAndroidPlatform();
if (platform == null) {
return;
}
classPath.remove(platform.getTarget().getPath(IAndroidTarget.ANDROID_JAR));
// Move the mockable android jar to the end.
String mockableJarPath = null;
for (String path : classPath.getPathList()) {
if (new File(FileUtil.toSystemDependentName(path)).getName().startsWith("mockable-android")) {
// PathsList stores strings - use the one that's actually stored there.
mockableJarPath = path;
break;
}
}
if (mockableJarPath != null) {
classPath.remove(mockableJarPath);
classPath.addTail(mockableJarPath);
}
}
Aggregations