编写自定义lint.xml

时间:2012-11-22 15:57:39

标签: android reporting lint

我们的Android项目依赖于一些我们无法控制的外部项目。因此,我正在尝试设置自定义lint.xml文件,以便我们可以为它们添加忽略规则。作为开始场景,我试图从ActionBarSherlock中删除警告(没有冒犯Jake)

<?xml version="1.0" encoding="UTF-8"?>
<lint>
  <issue id="FloatMath">
    <ignore path="app/target/classes/com/actionbarsherlock/*" />
  </issue>
  <issue id="DefaultLocale">
    <ignore path="app/target/classes/com/actionbarsherlock/*" />
  </issue>
  <issue id="ViewConstructor">
    <ignore path="app/target/classes/com/actionbarsherlock/*" />
  </issue>
</lint>

使用

中的以下命令
lint app --disable FloatMath,DefaultLocale,ViewConstructor --xml lint-result.xml

然而,制作的报告仍然包括来自ABS的消息。

更新 我把命令改为

lint --disable FloatMath,DefaultLocale,ViewConstructor --xml lint-result.xml app

对Jenkins不进行任何更改仍会生成相同的报告,无论忽略什么,但是如果在命令行中运行它会忽略禁用后列出的所有问题。我希望有简单的方法可以说,嘿,忽略/排除Maven所做的事情......

3 个答案:

答案 0 :(得分:10)

现在可以这样做:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
    <issue id="all">
        <ignore regexp="target/classes/com/actionbarsherlock/.*[.]class" />
    </issue>
</lint>

答案 1 :(得分:8)

再次回答我自己的问题...... lint.xml现在看起来像这样,它将忽略ASB 4.2.0上的任何ActionBarSherlock报告

<?xml version="1.0" encoding="UTF-8"?>
<lint>
  <issue id="NewApi">
    <ignore path="target/classes/com/actionbarsherlock/internal/ActionBarSherlockNative.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/ActionBarSherlockNative$ActionModeWrapper.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/app/ActionBarWrapper.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/app/ActionBarWrapper$TabWrapper.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/view/ActionProviderWrapper.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/view/menu/ActionMenuItemView.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/view/menu/MenuItemWrapper.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/view/menu/ActionMenuPresenter$HasPermanentMenuKey.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsAdapterView.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsProgressBar.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/ActionBarView$HomeView.class" />
    <ignore path="target/classes/com/actionbarsherlock/widget/SearchView.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/nineoldandroids/widget/NineFrameLayout.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/nineoldandroids/widget/NineHorizontalScrollView.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/nineoldandroids/widget/NineLinearLayout.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/nineoldandroids/view/NineViewGroup.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/view/menu/BaseMenuPresenter.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/AbsActionBarView.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/ActionBarContextView.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/ActionBarView.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/CapitalizingButton.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/CapitalizingTextView.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsAbsSpinner.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsLinearLayout.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsListPopupWindow.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/ScrollingTabContainerView.class" />
    <ignore path="target/classes/com/actionbarsherlock/widget/ActivityChooserView$SetActivated.class" />
    <ignore path="target/classes/com/actionbarsherlock/app/SherlockActivity.class" />
    <ignore path="target/classes/com/actionbarsherlock/app/SherlockExpandableListActivity.class" />
    <ignore path="target/classes/com/actionbarsherlock/app/SherlockListActivity.class" />
    <ignore path="target/classes/com/actionbarsherlock/app/SherlockPreferenceActivity.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/ActionBarSherlockNative$ActionModeCallbackWrapper.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/app/ActionBarImpl$1.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/app/ActionBarImpl.class" />
  </issue>

  <issue id="FloatMath">
    <ignore path="target/classes/com/actionbarsherlock/internal/nineoldandroids/view/animation/AnimatorProxy.class" />
  </issue>

  <issue id="DefaultLocale">
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/CapitalizingTextView.class" />
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/CapitalizingButton.class" />
  </issue>

  <issue id="ViewConstructor">
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/CollapsibleActionViewWrapper.class" />
  </issue>

  <issue id="WrongCall">
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsAdapterView.class" />
  </issue>
</lint>

我们现在使用的Shell执行命令是

lint --config lint.xml --xml lint-results.xml .;

PS:请注意,这不会删除所有排除APKLIB的报告,就像在这种情况下ABS一样,因为到目前为止无法将报告排除在R.class的未使用资源之外。在编译过程中,链接库的R.class和你的项目会合并,Lint无法知道这一点。它只看到单个R.class,其中包含一些未使用的引用并报告它们。

答案 2 :(得分:1)

我已完成lint.xml文件以排除更多actionbarsherlock错误。但是,有一个排除包机制会很好。

<?xml version="1.0" encoding="UTF-8"?>
<lint>
  <issue id="NewApi">
    <ignore path="target/classes/com/actionbarsherlock/internal/ActionBarSherlockNative.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/ActionBarSherlockNative$ActionModeWrapper.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/app/ActionBarWrapper.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/app/ActionBarWrapper$TabWrapper.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/view/ActionProviderWrapper.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/view/menu/ActionMenuItemView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/view/menu/MenuItemWrapper.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/view/menu/ActionMenuPresenter$HasPermanentMenuKey.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsAdapterView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsProgressBar.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/ActionBarView$HomeView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/widget/SearchView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/AbsActionBarView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/ActionBarContextView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/app/ActionBarImpl$1.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/app/ActionBarImpl.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/ActionBarSherlockNative$ActionModeCallbackWrapper.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/ActionBarView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/widget/ActivityChooserView$SetActivated.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/view/menu/BaseMenuPresenter.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/CapitalizingButton.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/CapitalizingTextView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsAbsSpinner.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsLinearLayout.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/IcsListPopupWindow.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/nineoldandroids/widget/NineHorizontalScrollView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/nineoldandroids/widget/NineLinearLayout.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/nineoldandroids/view/NineViewGroup.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/ScrollingTabContainerView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/app/SherlockActivity.class"/>
    <ignore path="target/classes/com/actionbarsherlock/app/SherlockExpandableListActivity.class"/>
    <ignore path="target/classes/com/actionbarsherlock/app/SherlockListActivity.class"/>
    <ignore path="target/classes/com/actionbarsherlock/app/SherlockPreferenceActivity.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/nineoldandroids/widget/NineFrameLayout.class"/>
    <ignore path="target/classes/com/viewpagerindicator/IcsLinearLayout.class"/>
</issue>

<issue id="FloatMath">
    <ignore path="target/classes/com/actionbarsherlock/internal/nineoldandroids/view/animation/AnimatorProxy.class"/>
</issue>

<issue id="DefaultLocale">
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/CapitalizingTextView.class"/>
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/CapitalizingButton.class"/>
</issue>

<issue id="ViewConstructor">
    <ignore path="target/classes/com/actionbarsherlock/internal/widget/CollapsibleActionViewWrapper.class"/>
</issue>
</lint>