Skip to content

Resolve iOS build errors by opting in to ExperimentalNativeApi

Problem

Running the iosApp from Android studio yields a failed build with several error messages: This declaration needs opt-in

> Task :src:compileKotlinIosSimulatorArm64
note: Using Kotlin home directory dist/kotlinc
/Users/jq/dev/wally/src/src/commonMain/kotlin/account.kt:110:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/account.kt:112:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/account.kt:114:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/account.kt:148:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/account.kt:150:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/account.kt:197:24: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/account.kt:204:25: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/account.kt:279:24: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/account.kt:292:24: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:107:28: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:110:32: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:121:32: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:128:32: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:137:28: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:147:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:467:28: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:491:32: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:505:36: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:512:43: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/app.kt:515:36: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/bitcoincomapi.kt:67:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/bitcoincomapi.kt:70:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/bitcoincomapi.kt:100:16: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/bitcoincomapi.kt:103:16: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/utils.kt:126:24: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/wallywalletorgapi.kt:82:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/wallywalletorgapi.kt:127:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'
/Users/jq/dev/wally/src/src/commonMain/kotlin/wallywalletorgapi.kt:130:20: error: This declaration needs opt-in. Its usage must be marked with '@kotlin.experimental.ExperimentalNativeApi' or '@OptIn(kotlin.experimental.ExperimentalNativeApi::class)'

> Task :src:compileKotlinIosSimulatorArm64 FAILED
error: Compilation finished with errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':src:compileKotlinIosSimulatorArm64'.
> Compilation finished with errors

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 5s
3 actionable tasks: 3 executed

Solution: Add the ExperimentalNativeApi freeCompilerArg to all iOS targets:

compilerOptions.options.freeCompilerArgs.add("-Xopt-in=kotlin.experimental.ExperimentalNativeApi")
Edited by Jørgen Svennevik Notland

Merge request reports