use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.
the class AndroidVirtualDeviceTest method testCreateDevice.
public void testCreateDevice() throws Exception {
MockFileOp fop = new MockFileOp();
recordPlatform23(fop);
recordGoogleApisAddon23(fop);
recordGoogleApisSysImg23(fop);
fop.recordExistingFile(new File(DeviceArtDescriptor.getBundledDescriptorsFolder(), "nexus_5x"));
AndroidSdkHandler sdkHandler = new AndroidSdkHandler(new File("/sdk"), new File("/android-home"), fop);
final AvdManagerConnection connection = new AvdManagerConnection(sdkHandler);
FakePackage.FakeRemotePackage remotePlatform = new FakePackage.FakeRemotePackage("platforms;android-23");
RepoFactory factory = AndroidSdkHandler.getRepositoryModule().createLatestFactory();
DetailsTypes.PlatformDetailsType platformDetailsType = factory.createPlatformDetailsType();
platformDetailsType.setApiLevel(23);
remotePlatform.setTypeDetails((TypeDetails) platformDetailsType);
Map<String, RemotePackage> remotes = Maps.newHashMap();
remotes.put("platforms;android-23", remotePlatform);
AndroidVirtualDevice avd = new AndroidVirtualDevice(new ScopedStateStore(ScopedStateStore.Scope.STEP, null, null), remotes, true, fop);
final AvdInfo avdInfo = avd.createAvd(connection, sdkHandler);
assertNotNull(avdInfo);
disposeOnTearDown(() -> connection.deleteAvd(avdInfo));
assertNotNull(avdInfo);
Map<String, String> properties = avdInfo.getProperties();
Map<String, String> referenceMap = getReferenceMap();
for (Map.Entry<String, String> entry : referenceMap.entrySet()) {
assertEquals(entry.getKey(), entry.getValue(), FileUtil.toSystemIndependentName(properties.get(entry.getKey())));
}
// AVD manager will set some extra properties that we don't care about and that may be system dependant.
// We do not care about those so we only ensure we have the ones we need.
File skin = new File(properties.get(AvdManager.AVD_INI_SKIN_PATH));
assertEquals("nexus_5x", skin.getName());
}
use of com.android.sdklib.repository.AndroidSdkHandler 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 com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.
the class UpgradeConstraintLayoutFix method apply.
public static void apply(@Nullable Module module) {
if (module != null) {
StudioSdkUtil.reloadRemoteSdkWithModalProgress();
AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(AndroidLintMissingConstraintsInspection.class);
RepoPackage p = SdkMavenRepository.findLatestVersion(LATEST_KNOWN_VERSION, sdkHandler, progress);
if (p != null) {
GradleCoordinate gc = SdkMavenRepository.getCoordinateFromSdkPath(p.getPath());
if (gc != null) {
// should always be the case unless the version suffix is somehow wrong
// Update version dependency in the module. Note that this will trigger a sync too.
GradleDependencyManager manager = GradleDependencyManager.getInstance(module.getProject());
manager.updateLibrariesToVersion(module, Collections.singletonList(gc), null);
}
}
}
}
use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.
the class AvdWizardUtilsTest method createMockSdk.
@NotNull
private static AndroidSdkHandler createMockSdk(String versionString, String path) {
FakeLocalPackage p = new FakeLocalPackage(path);
p.setRevision(Revision.parseRevision(versionString));
RepositoryPackages packages = new RepositoryPackages();
packages.setLocalPkgInfos(ImmutableList.of(p));
RepoManager mgr = new FakeRepoManager(null, packages);
return new AndroidSdkHandler(null, null, new MockFileOp(), mgr);
}
use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.
the class GradleImport method getBuildToolsVersion.
String getBuildToolsVersion() {
AndroidSdkHandler sdkHandler = AndroidSdkHandler.getInstance(mySdkLocation);
StudioLoggerProgressIndicator progress = new StudioLoggerProgressIndicator(getClass());
BuildToolInfo buildTool = sdkHandler.getLatestBuildTool(progress, false);
if (buildTool == null) {
buildTool = sdkHandler.getLatestBuildTool(progress, true);
}
if (buildTool != null) {
return buildTool.getRevision().toString();
}
return CURRENT_BUILD_TOOLS_VERSION;
}
Aggregations