2012-11-22 107 views
9

我們的Android項目是依賴於作爲我們沒有控制一些外部項目。因此,我正在嘗試設置自定義lint.xml文件,以便我們可以爲它們添加忽略規則。作爲起始場景我試圖從ActionBarSherlock在編寫自定義lint.xml

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

刪除警告(沒有進攻傑克)

<?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> 

用下面的命令但是生產報告還包括來自ABS的消息。

更新 我改變命令

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

不會使詹金斯的任何變化仍然會產生相同的報告,無論是什麼忽略,但如果在它的命令行運行忽略列出的所有問題禁用後。我希望有一種簡單的方式來說,嘿忽略/排除事情的方式Maven做...

+0

我把你的答案的'lint.xml'到我的項目的根。雖然沒有改變。你使用'mvn android:lint'來運行Lint,或者你配置'maven-compiler-plugin'來在構建過程中執行Lint,如[這裏所述](http://blog.octo.com/en/add-皮棉的檢查對Android的Maven的建立/)?請添加您的配置。 – JJD

+0

我從Jenkins的shell調用lint作爲'lint --config lint.xml --xml lint-result.xml'。或者'lint --config lint.xml',如果你在本地運行。這樣你直接運行android lint工具。我沒有嘗試使用android maven插件,但我希望在配置中必須有一個地方來添加排除lint文件 –

回答

8

再次回答我自己的問題... lint.xml看起來像這樣,它會忽略任何ActionBarSherlock對ASB 4.2.0報告

<?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> 

,我們現在用的是殼牌執行命令

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

PS:請注意,這不會刪除排除APKLIB的所有報告就像在這種情況下,如ABS到目前爲止,沒有辦法將報告排除在外R.class未使用的資源。在編譯過程R.class的鏈接庫和你的項目做合併,林特沒有辦法知道這一點。它只會看到一些沒有使用的引用R.class並報告它們。

+0

太棒了,但不完整。 Lint應該有一個排除類的機制... – Snicolas

+0

Snicolas我同意,谷歌需要更多地拋光它,因爲列出項目「附加」庫的所有類只是瘋狂的房子。其次,這並不能解決圖書館 –

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> 
+0

帶來的未使用資源的R.class報告問題,正如我所說的那樣,這隻會照顧類。如果您檢查lint結果報告,您會發現有大量未使用的資源與R類相關聯 –

9

現在,可以這樣做:

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