修复 Android Kotlin 构建配置#771
Merged
Merged
Conversation
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

修复 Android Kotlin Gradle 脚本编译错误
问题说明
在 Flutter 项目中通过 Git 依赖使用 fluwx 6.0.0 时,Android 构建失败:
错误位置:
kotlin { compilerOptions { jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 } }原因分析
当前构建脚本根据 Android Gradle Plugin 版本动态应用 Kotlin 插件:
由于 Kotlin 插件通过
apply(plugin = ...)动态应用,Kotlin DSL 在脚本编译阶段无法生成并识别以下类型安全访问器:kotlin { compilerOptions { // ... } }同时,构建脚本下方已经存在兼容动态插件加载方式的 JVM Target 配置:
project.extensions.configure( org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension::class.java ) { compilerOptions { jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 } }两段代码配置了相同的
JVM_17。前一段属于重复配置,并且会导致 Kotlin DSL 脚本编译失败。修改内容
删除无法解析的重复配置:
kotlin { compilerOptions { jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 } }保留兼容动态插件加载方式的配置:
project.extensions.configure( org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension::class.java ) { compilerOptions { jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 } }本次修改不改变实际的 JVM Target,仍然使用 Java 17。
测试方式
在 Flutter 项目中通过 Git 依赖引用修改后的 fluwx,然后执行:
测试结果
Android Debug APK 构建成功。
兼容性说明
JVM_17;