如何在KMM共享库中定制合成PodFile



我在构建kmm共享库时遇到了一些问题。这是由于平台版本。这是我的podspec文件

共享/构建/cocoapods/合成/IOS/豆荚/吊舱。xcodeproj: warning: iOS部署目标'IPHONEOS_DEPLOYMENT_TARGET'设置为10.0,但支持的部署目标版本范围为11.0 ~ 16.1.99。(在目标'FirebaseCore'从项目'Pods')

Pod::Spec.new do |spec|
spec.name                     = 'shared'
spec.version                  = '1.0'
spec.homepage                 = 'Link to the Shared Module homepage'
spec.source                   = { :http=> ''}
spec.authors                  = ''
spec.license                  = ''
spec.summary                  = 'Test'
spec.vendored_frameworks      = 'build/cocoapods/framework/shared.framework'
spec.libraries                = 'c++'
spec.ios.deployment_target = '14.1'
spec.dependency 'FirebaseAnalytics'
spec.dependency 'FirebaseAppCheck'
spec.dependency 'FirebaseAuth'
spec.dependency 'FirebaseCore'
spec.dependency 'FirebaseCrashlytics'
spec.dependency 'FirebaseFirestore'
spec.dependency 'FirebaseMessaging'
spec.dependency 'FirebaseRemoteConfig'
spec.dependency 'FirebaseStorage'
spec.dependency 'SQLCipher'

spec.pod_target_xcconfig = {
'KOTLIN_PROJECT_PATH' => ':shared',
'PRODUCT_MODULE_NAME' => 'shared',
}

spec.script_phases = [
{
:name => 'Build shared',
:execution_position => :before_compile,
:shell_path => '/bin/sh',
:script => <<-SCRIPT
if [ "YES" = "$COCOAPODS_SKIP_KOTLIN_BUILD" ]; then
echo "Skipping Gradle build task invocation due to COCOAPODS_SKIP_KOTLIN_BUILD environment variable set to "YES""
exit 0
fi
set -ev
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"
SCRIPT
}
]

end

生成的podfile在…/shared/build/cocoapods/synthetic/IOS

source 'https://cdn.cocoapods.org'
target 'ios' do
use_frameworks!
pod 'FirebaseAnalytics'
pod 'FirebaseAppCheck'
pod 'FirebaseAuth'
pod 'FirebaseCore'
pod 'FirebaseCrashlytics'
pod 'FirebaseFirestore'
pod 'FirebaseMessaging'
pod 'FirebaseRemoteConfig'
pod 'FirebaseStorage'
pod 'SQLCipher'
end
我可以像这样修改这个文件(不是手动的)吗
source 'https://cdn.cocoapods.org'
target 'ios' do
use_frameworks!
platform :ios, '14.1'
pod 'FirebaseAnalytics'
pod 'FirebaseAppCheck'
pod 'FirebaseAuth'
pod 'FirebaseCore'
pod 'FirebaseCrashlytics'
pod 'FirebaseFirestore'
pod 'FirebaseMessaging'
pod 'FirebaseRemoteConfig'
pod 'FirebaseStorage'
pod 'SQLCipher'
end
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.1'
config.build_settings['ENABLE_BITCODE'] = 'Yes'
config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf-with-dsym'
config.build_settings['VALID_ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
end
end
end

我在Xcode从14.2升级到14.3后面临同样的问题,我在这里试图找到一个解决方案。

正如您所说,您必须更新共享构建文件夹中自动生成的project.pbxproj文件。可以通过在共享代码build.gradle.kts脚本中添加一个新任务来实现。比如:

tasks.withType<PodGenTask>().configureEach {
doLast {
val xcodeprojFiles = listOf(
"Pods/Pods.xcodeproj",
"synthetic.xcodeproj",
)
for (xcodeprojFile in xcodeprojFiles) {
val file = project.buildDir.resolve("cocoapods/synthetic/${family.name}/$xcodeprojFile/project.pbxproj")
setIosDeploymentTarget(file)
}
}
}

这个脚本将处理:

  • build/cocoapods/synthetic/IOS/Pods/Pods.xcodeproj/project.pbxproj
  • build/cocoapods/synthetic/IOS/synthetic.xcodeproj/project.pbxproj

确保这些是您需要处理或更新文件列表以匹配您的项目配置的文件。

当然,您还需要提供setIosDeploymentTarget函数:

fun Project.setIosDeploymentTarget(
xcodeprojFile: File,
source: String = "10.0",
target: String = "14.1",
) {
val lines = xcodeprojFile.readLines()
val out = xcodeprojFile.bufferedWriter()
out.use {
for (line in lines) {
out.write(line.replace("IPHONEOS_DEPLOYMENT_TARGET = $source;", "IPHONEOS_DEPLOYMENT_TARGET = $target;"))
out.write(("n"))
}
}
}

函数附加两个参数sourcetarget,默认值分别为"10.0""14.1"

来源:https://youtrack.jetbrains.com/issue/kt - 57741

希望有帮助。

最新更新