在defaultConfig配置manifestPlaceholders遇Val无法重新赋值等错误求助
解决Auth0配置在build.gradle.kts中的报错问题
你当前用的是**Kotlin DSL(build.gradle.kts)**构建脚本,但指南给的是Groovy语法的代码,这就是所有报错的根源。
报错原因拆解
- Val cannot be reassigned:Kotlin DSL里
manifestPlaceholders是只读属性,不能直接用=赋值,得用+=的方式添加配置。 - Unresolved reference: auth0Domain、Expecting ']':Groovy里
[key: value]的Map写法在Kotlin里不生效,Kotlin需要用mapOf()包裹,键值对用to连接。 - Unexpected tokens:还是Groovy与Kotlin的语法差异导致的解析错误。
正确的配置代码
把defaultConfig里的相关代码换成下面的Kotlin DSL写法:
defaultConfig { applicationId = "com.example.myapplication" minSdk = 24 targetSdk = 33 versionCode = 1 versionName = "1.0" // 正确配置manifestPlaceholders的方式 manifestPlaceholders += mapOf( "auth0Domain" to "@string/com_auth0_domain", "auth0Scheme" to "@string/com_auth0_scheme" ) testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { useSupportLibrary = true } }
额外提醒
检查下你模块的构建脚本后缀:如果是build.gradle就是Groovy语法,build.gradle.kts是Kotlin语法。官方Demo如果用的是Groovy,代码自然和你的Kotlin脚本不兼容,换上面的写法就能解决所有问题。
内容的提问来源于stack exchange,提问作者stoneface
相关产品推荐
相关产品推荐

