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

KMM共享库pod lib lint校验失败,请求排查解决

KMM共享库发布CocoaPods失败排查

我们遵循KMM文档构建了一款支持iOS和Android的共享库,手动集成到iOS项目中可正常运行,但尝试发布到CocoaPods时遇到报错。执行pod lib lint shared/shared.podspec --verbose命令返回错误,相关日志如下:

Pod Lint错误日志

Testing with xcodebuild.
-> shared (0.3)

- WARN  | url: The URL (https://github.com/OUR_REPO_URL) is not reachable.
- WARN  | http: The URL (``) doesn't use the encrypted HTTPS protocol. It is crucial for Pods to be transferred over a secure protocol to protect your users from man-in-the-middle attacks. This will be an error in future releases. Please update the URL to use https.
- WARN  | [iOS] license: Unable to find a license file
- ERROR | [iOS] xcodebuild: Returned an unsuccessful exit code.
- NOTE  | xcodebuild:  note: Using new build system
- NOTE  | xcodebuild:  note: Using codesigning identity override: -
- NOTE  | xcodebuild:  note: Build preparation complete
- NOTE  | [iOS] xcodebuild:  note: Planning
- NOTE  | [iOS] xcodebuild:  note: Building targets in dependency order
- NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')

追溯到的Gradle构建报错

/bin/sh -c /Users/andreadg/Library/Developer/Xcode/DerivedData/App-aamafucqqbvtfsfaselpdjormnrg/Build/Intermediates.noindex/Pods.build/Release-iphonesimulator/shared.build/Script-46EB2E000002E0.sh
REPO_ROOT="$PODS_TARGET_SRCROOT"
"$REPO_ROOT/../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework                     -Pkotlin.native.cocoapods.platform=$PLATFORM_NAME                     -Pkotlin.native.cocoapods.archs="$ARCHS"                     -Pkotlin.native.cocoapods.configuration="$CONFIGURATION"

FAILURE: Build failed with an exception.

* What went wrong:
Directory '/' does not contain a Gradle build.

A Gradle build should contain a 'settings.gradle' or 'settings.gradle.kts' file in its root directory. It may also contain a 'build.gradle' or 'build.gradle.kts' file.

To create a new Gradle build in this directory run 'gradlew init'

此外,执行pod repo push同样失败;忽略校验手动发布后,库可安装但iOS项目构建仍报错,kdoctor检测无异常。


问题排查与解决方案

1. 核心问题:Gradle路径解析错误

报错Directory '/' does not contain a Gradle build说明构建脚本中$REPO_ROOT或$KOTLIN_PROJECT_PATH变量为空,导致Gradle找不到项目根目录:

  • 检查shared.podspec中的source配置,确保指向可正常访问的仓库地址,修复URL不可达的警告
  • 确认podspec内的KOTLIN_PROJECT_PATH参数正确,KMM生成的podspec默认会自动配置该路径,若手动修改过需确保其指向共享库模块的相对路径(比如../shared,需匹配你的项目结构)
  • 验证$PODS_TARGET_SRCROOT的取值逻辑:该变量应指向pod的源码目录,需确保podspec中source_files等路径配置正确,避免路径解析异常

2. 次要警告修复(避免未来版本报错)

  • HTTPS协议要求:检查podspec中所有URL字段(如homepage、source),全部替换为HTTPS协议,移除空的URL配置项
  • 许可证文件缺失:在项目根目录添加LICENSE文件,并在podspec中通过license字段指定,示例:
    license = { :type => 'Apache-2.0', :file => 'LICENSE' }
    

3. 其他构建警告处理

iOS项目的Info.plist警告:确保用于测试的iOS项目有正确的Info.plist文件,或在Xcode项目设置中开启“自动生成Info.plist”选项


内容的提问来源于stack exchange,提问作者user17439252

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 18:35:14