Compose Multi Platform iOS项目手动集成Lottie.xcframework后无法导入lottie包的问题求助
Compose Multi Platform iOS项目手动集成Lottie.xcframework后无法导入lottie包的问题求助
大家好,我最近在Compose Multi Platform(CMP)的iOS端项目里尝试手动集成Lottie动画,不想用Kottie这类第三方封装库,打算直接基于官方的Lottie.xcframework来实现,但遇到了导入问题,想请大家帮忙看看。
我已经完成的操作:
- 下载了官方的Lottie.xcframework,放到了项目的
libs目录下 - 在
src/iosMain/cinterop目录下创建了Lottie.def文件 - 在项目的
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") } } }
- 已经在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
相关产品推荐
相关产品推荐

