(#) Unsafe opt-in usage intended to be error-level severity
!!! ERROR: Unsafe opt-in usage intended to be error-level severity
This is an error.
Id
: `UnsafeOptInUsageError`
Summary
: Unsafe opt-in usage intended to be error-level severity
Severity
: Error
Category
: Correctness
Platform
: Any
Vendor
: Android Open Source Project
Identifier
: androidx.annotation.experimental
Feedback
: https://issuetracker.google.com/issues/new?component=459778
Min
: Lint 8.7+
Compiled
: Lint 8.7+
Artifact
: [androidx.annotation:annotation-experimental](androidx_annotation_annotation-experimental.md.html)
Since
: 1.1.0
Affects
: Kotlin and Java files
Editing
: This check runs on the fly in the IDE editor
Implementation
: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/annotation/annotation-experimental-lint/src/main/java/androidx/annotation/experimental/lint/ExperimentalDetector.kt)
Tests
: [Source Code](https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:/annotation/annotation-experimental-lint/src/test/kotlin/androidx/annotation/experimental/lint/ExperimentalDetectorTest.kt)
Copyright Year
: 2019
This API has been flagged as opt-in with error-level severity.
Any declaration annotated with this marker is considered part of an
unstable or
otherwise non-standard API surface and its call sites should accept the
opt-in
aspect of it by using the `@OptIn` annotation, using the marker
annotation --
effectively causing further propagation of the opt-in aspect -- or
configuring
the `UnsafeOptInUsageError` check's options for project-wide opt-in.
To configure project-wide opt-in, specify the `opt-in` option value in
`lint.xml`
as a comma-delimited list of opted-in annotations:
```
```
!!! Tip
This lint check has an associated quickfix available in the IDE.
(##) Including
!!!
This is not a built-in check. To include it, add the below dependency
to your project.
```
// build.gradle.kts
implementation("androidx.annotation:annotation-experimental:1.5.0-rc01")
// build.gradle
implementation 'androidx.annotation:annotation-experimental:1.5.0-rc01'
// build.gradle.kts with version catalogs:
implementation(libs.annotation.experimental)
# libs.versions.toml
[versions]
annotation-experimental = "1.5.0-rc01"
[libraries]
# For clarity and text wrapping purposes the following declaration is
# shown split up across lines, but in TOML it needs to be on a single
# line (see https://github.com/toml-lang/toml/issues/516) so adjust
# when pasting into libs.versions.toml:
annotation-experimental = {
module = "androidx.annotation:annotation-experimental",
version.ref = "annotation-experimental"
}
```
1.5.0-rc01 is the version this documentation was generated from;
there may be newer versions available.
[Additional details about androidx.annotation:annotation-experimental](androidx_annotation_annotation-experimental.md.html).
(##) Suppressing
You can suppress false positives using one of the following mechanisms:
* Using a suppression annotation like this on the enclosing
element:
```kt
// Kotlin
@Suppress("UnsafeOptInUsageError")
fun method() {
problematicStatement()
}
```
or
```java
// Java
@SuppressWarnings("UnsafeOptInUsageError")
void method() {
problematicStatement();
}
```
* Using a suppression comment like this on the line above:
```kt
//noinspection UnsafeOptInUsageError
problematicStatement()
```
* Using a special `lint.xml` file in the source tree which turns off
the check in that folder and any sub folder. A simple file might look
like this:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="UnsafeOptInUsageError" severity="ignore" />
</lint>
```
Instead of `ignore` you can also change the severity here, for
example from `error` to `warning`. You can find additional
documentation on how to filter issues by path, regular expression and
so on
[here](https://googlesamples.github.io/android-custom-lint-rules/usage/lintxml.md.html).
* In Gradle projects, using the DSL syntax to configure lint. For
example, you can use something like
```gradle
lintOptions {
disable 'UnsafeOptInUsageError'
}
```
In Android projects this should be nested inside an `android { }`
block.
* For manual invocations of `lint`, using the `--ignore` flag:
```
$ lint --ignore UnsafeOptInUsageError ...`
```
* Last, but not least, using baselines, as discussed
[here](https://googlesamples.github.io/android-custom-lint-rules/usage/baselines.md.html).