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

Kotlin Multiplatform iOS端Fastlane构建后App启动崩溃求助

解决Fastlane构建Kotlin Multiplatform Ad-hoc包启动崩溃问题

问题场景

我们的Kotlin Multiplatform应用通过Cocoapods打包shared模块,开发阶段和Xcode手动归档发布均正常,但使用Fastlane构建的Ad-hoc包上传到App Center后,设备启动即崩溃。

崩溃日志

ASI found [dyld] (sensitive) 'Library not loaded: @rpath/shared.framework/shared
Referenced from: <1BD25F02-DE04-35D4-BE94-37A6A7D3A268> /private/var/containers/Bundle/Application/B78CBDBE-5C0D-45E9-9CE9-E55D1A56166D/iosApp.app/iosApp
Reason: tried: '/usr/lib/swift/shared.framework/shared' (no such file, not in dyld cache), ...

相关配置

Podfile

target 'iosApp' do
  use_frameworks!
  platform :ios, '16.2'
  pod 'AppCenter'
  pod 'MaterialDesignSymbol'
  pod 'SwiftLint'
  pod 'shared', :path => '../shared'
end

Fastlane Lane配置

desc "Push a new beta build to App Center"
lane :appcenter do
  # Fetch the list of all iOS devices your app is distributed to
  appcenter_fetch_devices(
    api_token: ENV["APPCENTER_API_TOKEN"],
    owner_name: ENV["APPCENTER_OWNER_NAME"],
    app_name: ENV["APPCENTER_IOS_APP_NAME"],
    destinations: "*",
    devices_file: "test-devices.txt"
  )

  # Ensure all devices are registered with Apple
  register_devices(devices_file: "test-devices.txt")

  # Provision test devices, download provisioning profile, and download signing certificate
  match(
    force_for_new_devices: true,
    type: "adhoc"
  )

  update_code_signing_settings(
    path: 'iosApp.xcodeproj',
    use_automatic_signing: false,
    team_id: ENV["sigh_com.example.myapp_adhoc_team-id"],
    profile_name: ENV["sigh_com.example.myapp_adhoc_profile-name"],
    code_sign_identity: ENV["sigh_com.example.myapp_adhoc_certificate-name"],
  )
  update_project_provisioning(
    xcodeproj: 'iosApp.xcodeproj',
    target_filter: "iosApp",
    profile: ENV["sigh_com.example.myapp_adhoc_profile-path"],
    code_signing_identity: ENV["sigh_com.example.myapp_adhoc_certificate-name"],
  )

  # Build the app
  gym(
    configuration: "Release",
    clean: true,
    include_symbols: false,
    include_bitcode: false,
  )

  # Upload the app
  appcenter_upload(
    release_notes: ENV["APPCENTER_CHANGELOG"],
  )
end

解决方案

1. 提前编译KMM Shared模块

Fastlane构建流程中需确保KMM的shared模块已生成iOS framework,在lane开头添加Gradle编译命令:

# 编译shared模块的Release版本iOS framework
sh "./gradlew :shared:iosFrameworkRelease"

2. 执行Pod Install更新依赖

避免Cocoapods引用路径错误,在编译前执行依赖安装:

pod_install

3. 修正Gym构建配置

明确指定Ad-hoc导出方式,补充导出配置确保framework被正确嵌入:

gym(
  configuration: "Release",
  clean: true,
  include_symbols: false,
  include_bitcode: false,
  export_method: "ad-hoc", # 明确导出类型
  export_options: {
    signingStyle: "manual",
    provisioningProfiles: {
      "com.example.myapp" => ENV["sigh_com.example.myapp_adhoc_profile-name"] # 替换为你的Bundle ID
    }
  }
)

4. 确认Xcode项目配置

检查iOS App Target的Build Phases:

  • 确保shared.framework在Embed Frameworks列表中
  • 勾选Code Sign On Copy选项

修改后的完整Lane示例

desc "Push a new beta build to App Center"
lane :appcenter do
  # 编译KMM shared模块
  sh "./gradlew :shared:iosFrameworkRelease"
  
  # 安装Cocoapods依赖
  pod_install

  # Fetch the list of all iOS devices your app is distributed to
  appcenter_fetch_devices(
    api_token: ENV["APPCENTER_API_TOKEN"],
    owner_name: ENV["APPCENTER_OWNER_NAME"],
    app_name: ENV["APPCENTER_IOS_APP_NAME"],
    destinations: "*",
    devices_file: "test-devices.txt"
  )

  # Ensure all devices are registered with Apple
  register_devices(devices_file: "test-devices.txt")

  # Provision test devices, download provisioning profile, and download signing certificate
  match(
    force_for_new_devices: true,
    type: "adhoc"
  )

  update_code_signing_settings(
    path: 'iosApp.xcodeproj',
    use_automatic_signing: false,
    team_id: ENV["sigh_com.example.myapp_adhoc_team-id"],
    profile_name: ENV["sigh_com.example.myapp_adhoc_profile-name"],
    code_sign_identity: ENV["sigh_com.example.myapp_adhoc_certificate-name"],
  )
  update_project_provisioning(
    xcodeproj: 'iosApp.xcodeproj',
    target_filter: "iosApp",
    profile: ENV["sigh_com.example.myapp_adhoc_profile-path"],
    code_signing_identity: ENV["sigh_com.example.myapp_adhoc_certificate-name"],
  )

  # Build the app
  gym(
    configuration: "Release",
    clean: true,
    include_symbols: false,
    include_bitcode: false,
    export_method: "ad-hoc",
    export_options: {
      signingStyle: "manual",
      provisioningProfiles: {
        "com.example.myapp" => ENV["sigh_com.example.myapp_adhoc_profile-name"]
      }
    }
  )

  # Upload the app
  appcenter_upload(
    release_notes: ENV["APPCENTER_CHANGELOG"],
  )
end

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 10:40:30