You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS Ventura M1下Kotlin Multiplatform生成XCFramework报错求助

解决KMM项目生成XCFramework时Could not initialize class llvm.llvm错误

问题原因

该错误多因LLVM工具链与MacOS Ventura不兼容,或Android Studio内置的Kotlin版本、LLVM组件存在系统适配缺陷导致。

解决方案

1. 升级Kotlin与Gradle版本

  • 打开项目根目录build.gradle.kts(或build.gradle),将Kotlin版本升级至1.8.0及以上:
    plugins {
        kotlin("multiplatform") version "1.8.22" apply false
    }
    
  • 更新Gradle wrapper版本到7.5及以上,修改gradle/wrapper/gradle-wrapper.properties:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
    

2. 手动指定LLVM工具链路径

若升级后问题仍存在,添加Xcode内置LLVM路径配置:

  • 确保已安装最新稳定版Xcode,并更新Command Line Tools
  • 在项目build.gradle.kts中添加配置:
    kotlin {
        targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget> {
            binaries.all {
                linkerOpts("-L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx")
                linkerOpts("-L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib")
            }
        }
    }
    

3. 清理缓存后重建

  • 执行命令清理Gradle缓存与构建产物:
    ./gradlew clean
    rm -rf ~/.gradle/caches
    
  • 重启Android Studio,重新执行assembleSharedCodeReleaseXCFramework任务

4. 适配Android Studio版本

Android Studio Dolphin(2021.3.1)发布于Ventura之前,存在系统适配局限:

  • 建议升级至Electric Eel及以上版本的Android Studio
  • 若暂不升级IDE,可在Preferences > Build, Execution, Deployment > Build Tools > Gradle中,选择使用本地安装的Gradle版本替代IDE内置版本

验证操作

完成配置后重新运行构建任务,若错误消失则问题解决。若仍有异常,检查Xcode Command Line Tools路径:

xcode-select --print-path

确保输出为/Applications/Xcode.app/Contents/Developer,否则执行:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

内容的提问来源于stack exchange,提问作者Xavier Duvan Melo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 20:50:53