use of com.android.tools.idea.gradle.util.LocalProperties in project android by JetBrains.
the class GradleProjectSyncData method needsAndroidSdkSync.
private static boolean needsAndroidSdkSync(@NotNull final Project project) {
if (IdeInfo.getInstance().isAndroidStudio()) {
final File ideSdkPath = IdeSdks.getInstance().getAndroidSdkPath();
if (ideSdkPath != null) {
try {
LocalProperties localProperties = new LocalProperties(project);
File projectSdkPath = localProperties.getAndroidSdkPath();
return projectSdkPath == null || !filesEqual(ideSdkPath, projectSdkPath);
} catch (IOException ignored) {
}
}
return true;
}
return false;
}
use of com.android.tools.idea.gradle.util.LocalProperties in project android by JetBrains.
the class GradleBuildInvoker method executeTasks.
public void executeTasks(@NotNull List<String> gradleTasks, @NotNull List<String> commandLineArguments) {
List<String> jvmArguments = new ArrayList<>();
if (ApplicationManager.getApplication().isUnitTestMode()) {
// Projects in tests may not have a local.properties, set ANDROID_HOME JVM argument if that's the case.
LocalProperties localProperties;
try {
localProperties = new LocalProperties(myProject);
} catch (IOException e) {
throw new RuntimeException(e);
}
if (localProperties.getAndroidSdkPath() == null) {
File androidHomePath = IdeSdks.getInstance().getAndroidSdkPath();
// In Android Studio, the Android SDK home path will never be null. It may be null when running in IDEA.
if (androidHomePath != null) {
jvmArguments.add(AndroidGradleSettings.createAndroidHomeJvmArg(androidHomePath.getPath()));
}
}
}
Request request = new Request(myProject, gradleTasks);
// @formatter:off
request.setJvmArguments(jvmArguments).setCommandLineArguments(commandLineArguments);
// @formatter:on
executeTasks(request);
}
use of com.android.tools.idea.gradle.util.LocalProperties in project android by JetBrains.
the class GradleAndroidSdkEventListener method afterSdkPathChange.
/**
* Updates the path of the SDK manager in the project's local.properties file, only if the new path and the path in the file are
* different. This method will request a project sync, unless an error ocurred when updating the local.properties file.
*
* @param sdkPath the new Android SDK path.
* @param project one of the projects currently open in the IDE.
*/
@Override
public void afterSdkPathChange(@NotNull File sdkPath, @NotNull Project project) {
if (!isBuildWithGradle(project)) {
return;
}
LocalProperties localProperties;
try {
localProperties = new LocalProperties(project);
} catch (IOException e) {
// Exception thrown when local.properties file exists but cannot be read (e.g. no writing permissions.)
logAndShowErrorWhenUpdatingLocalProperties(project, e, "read", sdkPath);
return;
}
if (!filesEqual(sdkPath, localProperties.getAndroidSdkPath())) {
try {
localProperties.setAndroidSdkPath(sdkPath);
localProperties.save();
} catch (IOException e) {
logAndShowErrorWhenUpdatingLocalProperties(project, e, "update", sdkPath);
return;
}
}
if (!ApplicationManager.getApplication().isUnitTestMode()) {
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
}
}
use of com.android.tools.idea.gradle.util.LocalProperties in project android by JetBrains.
the class InstallNdkHyperlink method setNdkPath.
private static boolean setNdkPath(@NotNull Project project, @Nullable String ndkPath) {
LocalProperties localProperties;
try {
localProperties = new LocalProperties(project);
} catch (IOException e) {
String msg = String.format("Unable to read local.properties file of Project '%1$s':\n%2$s", project.getName(), e.getMessage());
Messages.showErrorDialog(project, msg, ERROR_TITLE);
return false;
}
try {
localProperties.setAndroidNdkPath(ndkPath == null ? null : new File(ndkPath));
localProperties.save();
} catch (IOException e) {
String msg = String.format("Unable to save local.properties file of Project '%1$s: %2$s", localProperties.getPropertiesFilePath().getPath(), e.getMessage());
Messages.showErrorDialog(project, msg, ERROR_TITLE);
return false;
}
return true;
}
use of com.android.tools.idea.gradle.util.LocalProperties in project android by JetBrains.
the class AndroidRunSdkToolAction method doAction.
public void doAction(@NotNull Project project) {
if (IdeInfo.getInstance().isAndroidStudio()) {
File androidHome = IdeSdks.getInstance().getAndroidSdkPath();
if (androidHome != null) {
doRunTool(project, androidHome.getPath());
return;
}
}
// Gradle project.
try {
LocalProperties localProperties = new LocalProperties(project);
File androidSdkPath = localProperties.getAndroidSdkPath();
if (androidSdkPath != null) {
doRunTool(project, androidSdkPath.getPath());
return;
}
} catch (IOException ignored) {
LOG.info(String.format("Unable to read local.properties file from project '%1$s'", project.getName()), ignored);
}
List<AndroidFacet> facets = ProjectFacetManager.getInstance(project).getFacets(AndroidFacet.ID);
assert facets.size() > 0;
Set<String> sdkSet = new HashSet<>();
for (AndroidFacet facet : facets) {
AndroidSdkData sdkData = facet.getConfiguration().getAndroidSdk();
if (sdkData != null) {
sdkSet.add(sdkData.getLocation().getPath());
}
}
if (sdkSet.size() == 0) {
Messages.showErrorDialog(project, AndroidBundle.message("specify.platform.error"), CommonBundle.getErrorTitle());
return;
}
String sdkPath = sdkSet.iterator().next();
if (sdkSet.size() > 1) {
String[] sdks = ArrayUtil.toStringArray(sdkSet);
int index = Messages.showChooseDialog(project, AndroidBundle.message("android.choose.sdk.label"), AndroidBundle.message("android.choose.sdk.title"), Messages.getQuestionIcon(), sdks, sdkPath);
if (index < 0) {
return;
}
sdkPath = sdks[index];
}
doRunTool(project, sdkPath);
}
Aggregations