Question

I am trying to create a plugin for Android Studio. From the plugin itself I have the reference to the project and the files via IntelliJ API but I can't get to gradle's build variant which user selected.

Is it possible to somehow get the build variant selected by user from the plugin code itself?

Was it helpful?

Solution

I would suggest you look at BuildVariantView.java, line 147 down.

Basically (skipping the null checks):

ModuleManager moduleManager = ModuleManager.getInstance(myProject);
Module module = ...; // Depending on your requirements
AndroidFacet androidFacet = AndroidFacet.getInstance(module);
IdeaAndroidProject ideaAndroidProject = androidFacet.getIdeaAndroidProject();
Variant variant = ideaAndroidProject.getSelectedVariant();

Please be sure to check that the module is both Android and Gradle project - especially if you wish for your plugin to work with IntelliJ Idea.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top