2017-10-30 4 views
0

Checker Frameworkを使用して、ランタイム時のNullabilityの失敗やUI制約の失敗などのアプリケーションの静的分析を行いたいとします。私はhttps://checkerframework.org/manual/#android-gradleの指示に従って実行しようとしましたが、checkTypesがタスクではないというエラーが表示されます。私は指示を正しく守ったと思うし、彼らが持っていた大文字の不一致を修正した。どのようにそれを修正するにはアイデア?私のbuild.gradleは以下の通りです:Androidでチェッカーフレームワークを実行する

buildscript { 
    repositories { 
     maven { url 'https://maven.fabric.io/public' } 
    } 

    dependencies { 
     classpath 'io.fabric.tools:gradle:1.+' 
    } 
} 
apply plugin: 'com.android.application' 
apply plugin: 'io.fabric' 

repositories { 
    maven { url 'https://maven.fabric.io/public' } 
    google() 
} 

apply plugin: 'jacoco' 
apply plugin: 'com.getkeepsafe.dexcount' 

gradle.projectsEvaluated { 
    tasks.withType(JavaCompile) { 
     options.compilerArgs << "-Xmaxerrs" << "500" 
    } 
} 

android { 
    compileSdkVersion 25 
    buildToolsVersion '26.0.2' 
    defaultConfig { 
     applicationId "com.handshake.hsdm" 
     minSdkVersion 19 
     targetSdkVersion 25 
     versionCode 35 
     versionName "0.0.35" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     multiDexEnabled true 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
      testCoverageEnabled = false 
     } 
     debug { 
      testCoverageEnabled = false 
     } 
     checkTypes { 
      javaCompileOptions.annotationProcessorOptions. 
        classNames.add("org.checkerframework.checker.guieffect.GuiEffectChecker") 
      // You can pass options like so: 
      // javaCompileOptions.annotationProcessorOptions.arguments.put("warns", "") 
     } 

    } 
    dexOptions { 
     preDexLibraries = false 
    } 
    sourceSets { 
     main { 
      manifest.srcFile 'src/main/AndroidManifest.xml' 
     } 
    } 
    packagingOptions { 
     //These files constantly step on each other from multiple libraries, don't include them 
     exclude 'META-INF/ASL2.0' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/*' 
     exclude 'plugin.xml' 
     exclude 'plugin.properties' 
     exclude 'about_files/LICENSE-2.0.txt' 
    } 
    testOptions { 
     unitTests.all { 
      jacoco { 
       includeNoLocationClasses = true 
      } 
     } 
    } 
    jacoco { 
     version = '0.7.3.201502191951' 
    } 
    configurations.all { 
     resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1' 
    } 
    compileOptions { 
     sourceCompatibility JavaVersion.VERSION_1_8 
     targetCompatibility JavaVersion.VERSION_1_8 
    } 

} 
configurations { 
    checkerFrameworkAnnotatedJDK { 
     description = 'a copy of JDK classes with Checker Framework type qualifers inserted' 
    } 
} 

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) { 

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

    def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*', 
         'com/handshake/hsdm/demo/**','com/handshake/hsdm/localstorage/schema1/*Dao*', 
         'com/handshake/hsdm/localstorage/schema1/*Factory*', 'com/handshake/hsdm/dagger2', 
         '**/*Module*', '**/*_Factory*', '**/*_MembersInjector*' 
    ] 
    def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter) 
    def mainSrc = "${project.projectDir}/src/main/java" 

    sourceDirectories = files([mainSrc]) 
    classDirectories = files([debugTree]) 
    executionData = fileTree(dir: "$buildDir", includes: [ 
      "jacoco/testDebugUnitTest.exec", 
      "outputs/code-coverage/connected/*coverage.ec" 
    ]) 

    afterEvaluate { 
     classDirectories = files(classDirectories.files.collect { 
      fileTree(dir: it, exclude: ['com/handshake/hsdm/demo/**']) 
     }) 
    } 
} 
dependencies { 
//Clipping dependencies 

    ext.checkerFrameworkVersion = '2.2.1' 
    implementation "org.checkerframework:checker-qual:${checkerFrameworkVersion}" 
    annotationProcessor "org.checkerframework:checker:${checkerFrameworkVersion}" 
    checkerFrameworkAnnotatedJDK "org.checkerframework:jdk8:${checkerFrameworkVersion}" 

} 
apply plugin: 'com.google.gms.google-services' 

gradle.projectsEvaluated { 
    tasks.withType(JavaCompile).all { compile -> 
     if (compile.name.contains("checkTypes")) { 
      compile.options.compilerArgs += [ 
        "-Xbootclasspath/p:${configurations.checkerFrameworkAnnotatedJDK.asPath}" 
      ] 
     } 
    } 
} 

編集:将来のために+ = [ "org.checkerframework.checker.nullness.NullnessChecker"]は問題があると思わラインjavaCompileOptions.annotationProcessorOptions.classNames readers-。それを削除すると、短剣やその他の注釈プロセッサが実行されますが、明らかにチェッカーは実行されません。

+0

どこでどのようにエラーが表示されますか? – CommonsWare

+0

gradlew checkTypesを実行しているとき。正確なメッセージは「*何が間違っていたか: タスク 'checkTypes'がルートプロジェクト 'HSDM'に見つかりませんでした。 –

+0

彼らのドキュメントは "チェッカーを実行するには、checkTypesバリアントを使用してビルドする"と言います。 'gradlew checkTypes'の下の行は間違っています。これはビルドタイプを構築する方法ではないので、' gradlew debug'を介して 'debug'ビルドを行う以上です。 'gradlew assembleDebug'または' gradlew installDebug'です。しかし、私は 'checkTypes 'のような大文字と小文字の混在型を試したことはありません。そのため、タスク名の組み立て方法はわかりません。 AndroidスタジオのGradleツールを確認し、そこにあるタスクを確認するか、コマンドラインでタスクを一覧表示し、表示される内容を確認します。 – CommonsWare

答えて

1

明らかに、クラス名を介して1つの注釈プロセッサを指定すると、他のものを上書きします。だから私は短剣とオートファクトも指定しなければなりませんでした。その後、Android Studioからビルドするか、コマンドラインからgradlew assembleCheckTypesを実行することができます

関連する問題