编写自定义lint.xml

我们的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不做任何改变仍然会产生相同的报告,不pipe忽略什么,但是如果在命令行中运行,它将忽略禁用后列出的所有问题。 我希望有一个简单的方法来说,嘿,忽视/排除事情Maven做的方式…

Solutions Collecting From Web of "编写自定义lint.xml"

现在可以这样做了:

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

再次回答我自己的问题… 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的链接库和你的项目做合并,林特没有办法知道这一点。 它只会看到一些没有使用的引用R.class并报告它们。

我已经完成了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>