如何导入javax.annotation.Nullable?

5

我使用Android Studio 3.x和Gradle构建脚本。

如何导入javax.annotation.*包?

下面是我的Gradle依赖项示例。

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:support-v4:27.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
2个回答

13
implementation 'com.google.code.findbugs:jsr305:3.0.2'

无论这是什么,都有效。 - undefined

2
如果您只需要注释功能,可以使用以下内容:

implementation "javax.annotation:jsr250-api:1.0"

但是在使用时需要非常小心,原因是这些类由多个库提供,例如:

implementation 'com.google.code.findbugs:jsr305:3.0.2'

implementation 'javax.inject:javax.inject:1'

implementation 'org.jetbrains.kotlin:kotlin-reflect:$versions.kotlin'

如果您已经使用了它们中的任何一个,请勿包含该库或使用exclude以避免任何构建错误。
implementation (org.jetbrains.kotlin:kotlin-reflect:$versions.kotlin){
        exclude module: 'jsr305'
        exclude module: 'jsr250'
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接