简体   繁体   中英

Android studio - creating plugin

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM