2015-11-07 56 views
1

我使用Android studio 1.4.1,我試圖設置findbugs,但是即使設置了排除xml R和Manifest findbugs仍然分析它們。Findbugs,retrolambda和Android

我想:

  1. 設置findbugs與Android,以避免R和所有這些生成的東西,像ViewBinderLambda

搖籃文件:

apply plugin: 'findbugs' 
apply plugin: 'pmd' 

findbugs { 
    ignoreFailures = true 
    reportsDir = file("$project.buildDir/outputs/") 
    reportLevel = "low" 
    effort = "max" 
    excludeFilter = file("../setup/findbugs-exclude.xml") 
} 

pmd { 
    ignoreFailures = true 
    reportsDir = file("$project.buildDir/outputs/") 
} 

task findbugs(type: FindBugs, dependsOn: assembleDebug) { 
    description 'Run findbugs' 
    group 'verification' 

    classes = fileTree("build/intermediates/classes/debug/") 
    source = fileTree('src/main/java') 
    classpath = files() 

    reports { 
    xml.enabled = false 
    html.enabled = true 
    } 
} 

task pmd(type: Pmd, dependsOn: assembleDebug) { 
    description 'Run pmd' 
    group 'verification' 

    ruleSets = ["java-basic", "java-braces", "java-strings", "java-design", "java-unusedcode"] 
    source = fileTree('src/main/java') 

    reports { 
    xml.enabled = false 
    html.enabled = true 
    } 
} 

check.doLast { 
    project.tasks.getByName("findbugs").execute() 
    project.tasks.getByName("pmd").execute() 
} 

FindBugs的-exclude.xml

<?xml version="1.0" encoding="UTF-8"?> 
<FindBugsFilter> 
    <Match> 
    <Class name="~.*\.R\$.*" /> 
    </Match> 
    <Match> 
    <Class name="~.*\.Manifest\$.*" /> 
    </Match> 
</FindBugsFilter> 

響應:

Code analyzed: 

/Users/me/Documents/test-android/app/build/intermediates/classes/debug/android/support/design/R$anim.class 
/Users/me/Documents/test-android/app/build/intermediates/classes/debug/android/support/design/R$attr.class 
/Users/me/Documents/test-android/app/build/intermediates/classes/debug/android/support/design/R$bool.class 
/Users/me/Documents/test-android/app/build/intermediates/classes/debug/android/support/design/R$color.class 
/Users/me/Documents/test-android/app/build/intermediates/classes/debug/android/support/design/R$dimen.class 
/Users/me/Documents/test-android/app/build/intermediates/classes/debug/android/support/design/R$drawable.class 
/Users/me/Documents/test-android/app/build/intermediates/classes/debug/android/support/design/R$id.class 
/Users/me/Documents/test-android/app/build/intermediates/classes/debug/android/support/design/R$integer.class 
/Users/me/Documents/test-android/app/build/intermediates/classes/debug/android/support/design/R$layout.class 
/Users/me/Documents/test-android/app/build/intermediates/classes/debug/android/support/design/R$string.class 

UPM Private method com.test.android.player.service.PlayerServicePresenter$$Lambda$1.get$Lambda(PlayerServicePresenter) is never called 
UPM Private method com.test.android.sign_up.SignUpActivity$$Lambda$1.get$Lambda(SignUpActivity) is never called 
UPM Private method com.test.android.sign_up.SignUpActivity$$Lambda$4.get$Lambda(SignUpActivity) is never called 
UPM Private method com.test.android.sign_up.SignUpPresenter$$Lambda$1.get$Lambda(SignUpPresenter) is never called 
UPM Private method com.test.android.sign_up.SignUpPresenter$$Lambda$2.get$Lambda(SignUpPresenter) is never called 
UPM Private method com.test.android.tutorial.TutorialActivity$$Lambda$1.get$Lambda(TutorialActivity) is never called 
UPM Private method com.test.android.tutorial.TutorialPresenter$$Lambda$1.get$Lambda(TutorialPresenter, String) is never called 
UPM Private method com.test.android.tutorial.TutorialPresenter$$Lambda$2.get$Lambda(TutorialPresenter) is never called 
UPM Private method com.test.android.tutorial.TutorialPresenter$$Lambda$3.get$Lambda(TutorialPresenter) is never called 
UPM Private method com.test.android.utils.base.BaseView$$Lambda$1.get$Lambda(BaseView) is never called 

回答

1

也許這將有助於。只需添加到FindBugs的-exclude.xml此代碼:

<Match> 
    <Bug code="UPM" /> 
    <Class name="~.*\$\$Lambda\$.*"/> 
</Match> 
+0

爲什麼我需要把標籤裏面?有沒有辦法避免這些類的所有檢查? – Caipivara

+0

這就像一個魅力,感謝兄弟! :d –