如何在Android应用中添加编译器参数?

发布于 2025-02-13 01:21:15 字数 232 浏览 1 评论 0原文

我正在使用撰写,某些方法需要@optin(persuctiment -foundationapi :: class)注释。
问题是,Android Studio在此注释中不断显示警告,并带有以下消息:应与编译器参数'-opt-in = kotlin.requiresoptin'一起使用此注释。
该代码正常工作,但我想做Android Studio建议删除此警告的事情。我该如何解决?

I'm using Compose and some methods require the @OptIn(ExperimentalFoundationApi::class) annotation.
The thing is that the Android Studio keeps showing a warning in this annotation with the following message: This annotation should be used with the compiler argument '-opt-in=kotlin.RequiresOptIn'.
The code works normally but I would like to do what Android Studio suggests to remove this warning. How can I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆凄凉。 2025-02-20 01:21:15

build.gradle中,您可以从应用模块中添加freecompilerargs +='-opt-in = kotlin.requiresoptin'内部kotlinoptions block。像这样:

plugins {
    // ...
}

android {
    // ...

    kotlinOptions {
        jvmTarget = '1.8'
        freeCompilerArgs += '-opt-in=kotlin.RequiresOptIn'
    }

    // ...
}

dependencies {
    // ...
}

In the build.gradle from app module you can add the freeCompilerArgs += '-opt-in=kotlin.RequiresOptIn' inside kotlinOptions block. Like this:

plugins {
    // ...
}

android {
    // ...

    kotlinOptions {
        jvmTarget = '1.8'
        freeCompilerArgs += '-opt-in=kotlin.RequiresOptIn'
    }

    // ...
}

dependencies {
    // ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文