use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.
the class InstantRunConfigurable method updateProjectToInstantRunTools.
/** Update versions relevant for Instant Run, and trigger a Gradle sync if successful */
public static boolean updateProjectToInstantRunTools(@NotNull Project project, @Nullable GradleSyncListener listener) {
String pluginVersion = MINIMUM_GRADLE_PLUGIN_VERSION_STRING;
// Pick max version of "recommended Gradle plugin" and "minimum required for instant run"
if (GradleVersion.parse(GRADLE_PLUGIN_RECOMMENDED_VERSION).compareTo(MINIMUM_GRADLE_PLUGIN_VERSION) > 0) {
pluginVersion = GRADLE_PLUGIN_RECOMMENDED_VERSION;
}
// Update plugin version
AndroidPluginVersionUpdater updater = AndroidPluginVersionUpdater.getInstance(project);
UpdateResult result = updater.updatePluginVersion(GradleVersion.parse(pluginVersion), GradleVersion.parse(GRADLE_LATEST_VERSION));
if (result.isPluginVersionUpdated() && result.versionUpdateSuccess()) {
// Should be at least 23.0.2
String buildToolsVersion = "23.0.2";
AndroidSdkHandler sdk = AndroidSdks.getInstance().tryToChooseSdkHandler();
BuildToolInfo latestBuildTool = sdk.getLatestBuildTool(new StudioLoggerProgressIndicator(InstantRunConfigurable.class), false);
if (latestBuildTool != null) {
Revision revision = latestBuildTool.getRevision();
if (revision.compareTo(Revision.parseRevision(buildToolsVersion)) > 0) {
buildToolsVersion = revision.toShortString();
}
}
// Also update build files to set build tools version 23.0.2
GradleUtil.setBuildToolsVersion(project, buildToolsVersion);
// Also update Gradle wrapper version
GradleWrapper gradleWrapper = GradleWrapper.find(project);
if (gradleWrapper != null) {
gradleWrapper.updateDistributionUrlAndDisplayFailure(GRADLE_LATEST_VERSION);
}
// Request a sync
GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setRunInBackground(false);
GradleSyncInvoker.getInstance().requestProjectSync(project, request, listener);
return true;
} else {
return false;
}
}
use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.
the class SdkBuildToolsTooLowErrorHandler method getQuickFixHyperlinks.
@NotNull
public List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull String minimumVersion, @NotNull Project project, @Nullable Module module) {
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
boolean buildToolInstalled = false;
AndroidSdkHandler sdkHandler = null;
AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (androidSdkData != null) {
sdkHandler = androidSdkData.getSdkHandler();
}
if (sdkHandler != null) {
ProgressIndicator progress = new StudioLoggerProgressIndicator(SdkBuildToolsTooLowErrorHandler.class);
RepositoryPackages packages = sdkHandler.getSdkManager(progress).getPackages();
LocalPackage buildTool = packages.getLocalPackages().get(getBuildToolsPath(parseRevision(minimumVersion)));
buildToolInstalled = buildTool != null;
}
if (module != null) {
VirtualFile buildFile = getGradleBuildFile(module);
AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(project);
if (!buildToolInstalled) {
if (androidPluginInfo != null && androidPluginInfo.isExperimental()) {
hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, null));
} else {
hyperlinks.add(new InstallBuildToolsHyperlink(minimumVersion, buildFile));
}
} else if (buildFile != null && androidPluginInfo != null && !androidPluginInfo.isExperimental()) {
hyperlinks.add(new FixBuildToolsVersionHyperlink(buildFile, minimumVersion));
}
if (buildFile != null) {
hyperlinks.add(new OpenFileHyperlink(buildFile.getPath()));
}
}
return hyperlinks;
}
use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.
the class MissingPlatformErrorHandler method findAndAddQuickFixes.
private void findAndAddQuickFixes(@NotNull NotificationData notification, @NotNull Project project, @NotNull String text) {
String missingPlatform = getMissingPlatform(text);
if (missingPlatform == null) {
return;
}
String loadError = null;
List<NotificationHyperlink> hyperlinks = new ArrayList<>();
AndroidSdkHandler sdkHandler = null;
AndroidSdkData androidSdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
if (androidSdkData != null) {
sdkHandler = androidSdkData.getSdkHandler();
}
if (sdkHandler != null) {
AndroidVersion version = AndroidTargetHash.getPlatformVersion(missingPlatform);
if (version != null) {
// Is the platform installed?
ProgressIndicator logger = new StudioLoggerProgressIndicator(getClass());
loadError = sdkHandler.getAndroidTargetManager(logger).getErrorForPackage(DetailsTypes.getPlatformPath(version));
hyperlinks.add(new InstallPlatformHyperlink(version));
}
}
if (hyperlinks.isEmpty()) {
// We are unable to install platform automatically.
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
if (!facets.isEmpty()) {
// We can only open SDK manager if the project has an Android facet. Android facet has a reference to the Android SDK manager.
hyperlinks.add(new OpenAndroidSdkManagerHyperlink());
}
}
if (isNotEmpty(loadError)) {
text += "\nPossible cause: " + loadError;
}
SyncMessages.getInstance(project).updateNotification(notification, text, hyperlinks);
}
use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.
the class FormFactorApiComboBox method loadRemoteTargets.
private void loadRemoteTargets(final int minSdkLevel, final Runnable completedCallback, final Runnable foundItemsCallback, final Runnable noItemsCallback) {
AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
final Runnable runCallbacks = () -> {
if (completedCallback != null) {
completedCallback.run();
}
if (getItemCount() > 0) {
if (foundItemsCallback != null) {
foundItemsCallback.run();
}
} else {
if (noItemsCallback != null) {
noItemsCallback.run();
}
}
};
RepoManager.RepoLoadedCallback onComplete = packages -> {
addPackages(packages.getNewPkgs(), minSdkLevel);
addOfflineLevels();
loadSavedApi();
runCallbacks.run();
};
// We need to pick up addons that don't have a target created due to the base platform not being installed.
RepoManager.RepoLoadedCallback onLocalComplete = packages -> addPackages(packages.getLocalPackages().values(), minSdkLevel);
Runnable onError = () -> ApplicationManager.getApplication().invokeLater(() -> {
addOfflineLevels();
runCallbacks.run();
}, ModalityState.any());
StudioProgressRunner runner = new StudioProgressRunner(false, false, "Refreshing Targets", true, null);
sdkHandler.getSdkManager(REPO_LOG).load(RepoManager.DEFAULT_EXPIRATION_PERIOD_MS, ImmutableList.of(onLocalComplete), ImmutableList.of(onComplete), ImmutableList.of(onError), runner, new StudioDownloader(), StudioSettingsController.getInstance(), false);
}
use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.
the class AndroidSdksTest method testTryToChooseSdkHandler.
public void testTryToChooseSdkHandler() {
myAndroidSdks.create(findAndroidTarget(), mySdkPath, myJdk, false);
AndroidSdkHandler sdkHandler = myAndroidSdks.tryToChooseSdkHandler();
AndroidSdkData sdkData = getSdkData(mySdkPath);
assertNotNull(sdkData);
assertSame(sdkData.getSdkHandler(), sdkHandler);
}
Aggregations