Android Nullaway框架,从此告别NPE

https://github.com/uber/NullAway


project gradle下

3.0以前,repositories标签下

添加maven { url 'https://maven.google.com' }

3.0以后添加google()


同时repositories标签下还要添加

maven {url "https://plugins.gradle.org/m2/"}


plugins {
  id "net.ltgt.errorprone" version "0.0.13"

}


dependencies {
        classpath deps.build.gradlePlugins.android//这个可能不用
        classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.13"
}


module gradle

apply plugin: 'com.android.application'

apply plugin: 'net.ltgt.errorprone'


android下

compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }


    lintOptions {
        abortOnError false
    }


dependencies下

errorprone "com.google.errorprone:error_prone_core:2.1.3"

annotationProcessor "com.uber.nullaway:nullaway:0.4.6"


tasks.withType(JavaCompile) {
  // remove the if condition if you want to run NullAway on test code
  if (!name.toLowerCase().contains("test")) {
    options.compilerArgs += ["-Xep:NullAway:ERROR", "-XepOpt:NullAway:AnnotatedPackages=com.uber"]
  }

}


红字的地方,是你要检索NPE的包,这是你需要修改的地方。


在sync now应用gardle后,你需要在terminal中

./gradlew build

这样你所有NPE的地方就会显示出来了


对于你可能有空指针的地方,希望你能用@Nullable、@NotNull、if语句进行修复



                
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值