Search in sources :

Example 1 with AndroidDslElement

use of com.android.tools.idea.gradle.dsl.parser.android.AndroidDslElement 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);
}
Also used : AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel) AndroidDslElement(com.android.tools.idea.gradle.dsl.parser.android.AndroidDslElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AndroidModel (com.android.tools.idea.gradle.dsl.model.android.AndroidModel)1 AndroidDslElement (com.android.tools.idea.gradle.dsl.parser.android.AndroidDslElement)1 AndroidPluginInfo (com.android.tools.idea.gradle.plugin.AndroidPluginInfo)1 Nullable (org.jetbrains.annotations.Nullable)1