How Do We Configure Android Studio to Run Its Lint on Every Build?

前端 未结 4 527
清酒与你
清酒与你 2020-12-12 19:21

Once upon a time, particularly in Eclipse-land, Lint would run on every build, and so if you failed Lint checks, you would find out immediately. With Android Studio (tested

4条回答
  •  时光取名叫无心
    2020-12-12 20:24

    One possible (but hard to implement) solution is to write an IDEA plugin to do this. You can avoid this by downloading the plugin below from the repository or the code from github. The following code snippet will execute the 'compile' and 'inspect code' actions, sequentially.

    public class BuildAndLint extends AnAction {
        public void actionPerformed(AnActionEvent e) {
            String[] actions = {"CompileProject", "InspectCode"};
            for(String action: actions) {
                AnAction anAction = ActionManager.getInstance().getAction(action);
    
                DataContext context = e.getDataContext(); 
                AnActionEvent anActionEvent = new AnActionEvent(null, context, "", anAction.getTemplatePresentation(), ActionManager.getInstance(), 0);
    
                anAction.actionPerformed(anActionEvent);
            }
        }
    }
    

    The code has been tested and works in Android Studio 1.3. It will open a window to select what to inspect, rather than doing the whole thing.

    Links

    Source code on github

    Built and Lint Jar

提交回复
热议问题