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

Compose Multi Platform iOS项目手动集成Lottie.xcframework后无法导入lottie包的问题求助

Compose Multi Platform iOS项目手动集成Lottie.xcframework后无法导入lottie包的问题求助

大家好,我最近在Compose Multi Platform(CMP)的iOS端项目里尝试手动集成Lottie动画,不想用Kottie这类第三方封装库,打算直接基于官方的Lottie.xcframework来实现,但遇到了导入问题,想请大家帮忙看看。

我已经完成的操作:

  1. 下载了官方的Lottie.xcframework,放到了项目的libs目录下
  2. 在src/iosMain/cinterop目录下创建了Lottie.def文件
  3. 在项目的build.gradle中针对不同iOS架构配置了cinterop,具体代码如下:
iosArm64 {
    compilations.getByName("main") {
        val Lottie by cinterops.creating {
            defFile("src/iosMain/cinterop/Lottie.def")
            val path = "$rootDir/libs/Lottie.xcframework/ios-arm64"
            compilerOpts("-F$path", "-framework", "Lottie", "-rpath", path)
            extraOpts += listOf("-compiler-option", "-fmodules")
        }
    }
}

listOf(
    iosX64(),
    iosSimulatorArm64()
).forEach {
    it.compilations.getByName("main") {
        val Lottie by cinterops.creating {
            defFile("src/iosMain/cinterop/Lottie.def")
            val path = "$rootDir/libs/Lottie.xcframework/ios-arm64_x86_64-simulator"
            compilerOpts("-F$path", "-framework", "Lottie", "-rpath", path)
            extraOpts += listOf("-compiler-option", "-fmodules")
        }
    }
}
  1. 已经在Xcode中将Lottie.xcframework添加到Frameworks,Libraries, and Embedded Content中,并且设置了Embed & Sign

遇到的问题:

我编写了对应的Compose actual函数后,发现完全无法识别lottie包,尝试添加import lottie.*时,IDE提示Unresolved reference 'lottie',我的Compose函数代码如下:

@Composable
actual fun LottieAnimation(
    modifier: Modifier,
    composition: Any?,
    progress: () -> Float,
    backgroundColor: Color,
    contentScale: ContentScale,
    clipToCompositionBounds: Boolean,
) {
}

我排查了很久,不确定是cinterop的配置哪里出了问题,还是有其他步骤遗漏了?有没有朋友遇到过类似的情况,能帮忙指点一下吗?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.08 12:19:36