use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.
the class ReferenceResolutionTest method testResolveRootProject.
public void testResolveRootProject() throws Exception {
String settingsText = "include ':" + SUB_MODULE_NAME + "'";
String mainModuleText = "android {\n" + " compileSdkVersion = \"android-23\"\n" + "}";
String subModuleText = "android {\n" + " compileSdkVersion = rootProject.android.compileSdkVersion\n" + "}";
writeToSettingsFile(settingsText);
writeToBuildFile(mainModuleText);
writeToSubModuleBuildFile(subModuleText);
AndroidModel androidModel = getGradleBuildModel().android();
assertNotNull(androidModel);
assertEquals("compileSdkVersion", "android-23", androidModel.compileSdkVersion());
AndroidModel subModuleAndroidModel = getSubModuleGradleBuildModel().android();
assertNotNull(subModuleAndroidModel);
assertEquals("compileSdkVersion", "android-23", subModuleAndroidModel.compileSdkVersion());
}
use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.
the class ReferenceResolutionTest method testResolveParent.
public void testResolveParent() throws Exception {
String settingsText = "include ':" + SUB_MODULE_NAME + "'";
String mainModuleText = "android {\n" + " compileSdkVersion = \"android-23\"\n" + "}";
String subModuleText = "android {\n" + " compileSdkVersion = parent.android.compileSdkVersion\n" + "}";
writeToSettingsFile(settingsText);
writeToBuildFile(mainModuleText);
writeToSubModuleBuildFile(subModuleText);
AndroidModel androidModel = getGradleBuildModel().android();
assertNotNull(androidModel);
assertEquals("compileSdkVersion", "android-23", androidModel.compileSdkVersion());
AndroidModel subModuleAndroidModel = getSubModuleGradleBuildModel().android();
assertNotNull(subModuleAndroidModel);
assertEquals("compileSdkVersion", "android-23", subModuleAndroidModel.compileSdkVersion());
}
use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.
the class GradleUtil method setBuildToolsVersion.
public static void setBuildToolsVersion(@NotNull Project project, @NotNull String version) {
List<GradleBuildModel> modelsToUpdate = Lists.newArrayList();
for (Module module : ModuleManager.getInstance(project).getModules()) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
GradleBuildModel buildModel = GradleBuildModel.get(module);
if (buildModel != null) {
AndroidModel android = buildModel.android();
if (android != null && !version.equals(android.buildToolsVersion().value())) {
android.setBuildToolsVersion(version);
modelsToUpdate.add(buildModel);
}
}
}
}
if (!modelsToUpdate.isEmpty()) {
runWriteCommandAction(project, () -> {
for (GradleBuildModel buildModel : modelsToUpdate) {
buildModel.applyChanges();
}
});
}
}
use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.
the class GradleBuildModel method android.
/**
* Returns {@link AndroidModel} to read and update android block contents in the build.gradle file.
*
* <p>Returns {@code null} when experimental plugin is used as reading and updating android section is not supported for the
* experimental dsl.</p>
*/
@Nullable
public AndroidModel android() {
AndroidPluginInfo androidPluginInfo = AndroidPluginInfo.find(myGradleDslFile.getProject());
if (androidPluginInfo != null && androidPluginInfo.isExperimental()) {
// Reading or updating Android block contents is not supported when experimental plugin is used.
return null;
}
AndroidDslElement androidDslElement = myGradleDslFile.getPropertyElement(ANDROID_BLOCK_NAME, AndroidDslElement.class);
if (androidDslElement == null) {
androidDslElement = new AndroidDslElement(myGradleDslFile);
myGradleDslFile.setNewElement(ANDROID_BLOCK_NAME, androidDslElement);
}
return new AndroidModel(androidDslElement);
}
use of com.android.tools.idea.gradle.dsl.model.android.AndroidModel in project android by JetBrains.
the class LinkExternalCppProjectDialog method doOKAction.
@Override
protected void doOKAction() {
String projectPath = toSystemIndependentName(myProjectPathTextField.getText().trim());
String relativePath = getPathRelativeToModuleDir(myModule, projectPath);
assert relativePath != null;
GradleBuildModel buildModel = GradleBuildModel.get(myModule);
assert buildModel != null;
AndroidModel android = buildModel.android();
assert android != null;
if (myBuildSystemCombo.getSelectedItem() == BuildSystem.CMAKE) {
android.externalNativeBuild().cmake().setPath(new File(relativePath));
} else {
android.externalNativeBuild().ndkBuild().setPath(new File(relativePath));
}
Project project = myModule.getProject();
new WriteCommandAction(project, "Link C++ Project with Gradle") {
@Override
protected void run(@NotNull Result result) throws Throwable {
buildModel.applyChanges();
}
}.execute();
GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
super.doOKAction();
}
Aggregations