Android/Jetpack Compose
[Android] This annotation should be used with the compiler argument '-opt-in=kotlin.RequiresOptIn' 해결하기
상추님
2022. 10. 9. 20:24
[Android] This annotation should be used with the compiler argument '-opt-in=kotlin.RequiresOptIn' 해결하기
Jetpack Compose 사용하여 개발을 할 때 실험 적인 기능, 일부 베타 기능을 사용할 때 아래와 같은 어노테이션을 적용하여 사용하게 된다.
@OptIn(ExperimentalMaterial3Api::class)
위 어노테이션 적용 후 빌드, 컴파일은 문제 없이 잘 되지만, 경고가 발생하여 좀 거슬렸다. 이를 제거하기 위해 app 수준 build.gradle 에 아래와 같은 옵션을 추가해준다.
android {
//...
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
}
}
//...
}
이후 sync 를 해주고 다시 돌아가보면 경고가 사라진 것을 볼 수 있다. 🫣
2022.10.09 - [Android/Groovy] - [Android Groovy] build.gradle plugins apply false? 왜 false 인가
2022.09.30 - [Android/Retrofit] - [Android] Retrofit HTTP Converter 결과값 파싱이 null 로 올 때 ☠️
2022.08.23 - [SELECT *] - [Android] 해상도별 drawable 이미지 리소스 추가하기 (dpi 별)