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

添加GitLive Firebase依赖后KMM应用构建失败,iOS端报错求助

解决KMM集成GitLive Firebase SDK的iOS构建及导入问题

问题核心分析

你遇到的ld: framework not found FirebaseAuth错误,本质是iOS端缺少原生FirebaseAuth框架的链接;而commonMain无法导入依赖则大概率是Gradle配置不完整或缓存问题。

分步解决方案

1. 修正Gradle依赖配置

在shared模块的build.gradle.kts中,确保commonMain和iOS目标的配置正确:

plugins {
    kotlin("multiplatform")
    id("com.android.library")
    id("dev.gitlive.firebase") version "1.12.0" // 必须添加GitLive的插件
}

kotlin {
    android()
    iosX64()
    iosArm64()

    sourceSets {
        val commonMain by getting {
            dependencies {
                // 添加需要的Firebase模块,版本与插件一致
                implementation("dev.gitlive:firebase-auth:1.12.0")
                implementation("dev.gitlive:firebase-core:1.12.0")
            }
        }
        // 其他sourceSets配置...
    }

    // 配置iOS的CocoaPods集成(必须,因为依赖原生Firebase框架)
    cocoapods {
        summary = "Shared KMM Module"
        homepage = "Your project homepage"
        ios.deploymentTarget = "14.0"
        // 引入对应版本的原生Firebase Pods,版本需与GitLive SDK兼容
        pod("FirebaseAuth") { version = "~> 10.22.0" }
        pod("FirebaseCore") { version = "~> 10.22.0" }
    }
}

注:GitLive插件版本需与Firebase SDK版本保持一致,版本兼容性可参考官方说明。

2. 重新同步并安装CocoaPods

  • 在Android Studio中执行Sync Project with Gradle Files
  • 打开终端,进入iOS项目目录(包含Podfile的文件夹),执行:
pod install
  • 之后必须打开iOS项目的.xcworkspace文件(而非.xcodeproj)

3. 解决commonMain导入问题

如果同步后仍无法导入依赖,执行以下操作清除缓存:

  • 执行Gradle清理命令:
./gradlew clean
  • 在Android Studio中点击File -> Invalidate Caches...,选择"Invalidate and Restart"

4. 确认iOS端Firebase初始化

在iOS项目的AppDelegate.swift或SceneDelegate.swift中添加Firebase初始化代码:

import Firebase

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    return true
}

5. 验证iOS构建配置

打开iOS项目的Build Phases:

  • 确认Link Binary With Libraries中包含FirebaseAuth.framework和FirebaseCore.framework(CocoaPods会自动添加,若缺失可手动从Pods目录添加)

关键注意事项

  • 不要混用framework模式和CocoaPods模式:GitLive的Firebase SDK依赖原生Firebase框架,必须通过CocoaPods集成,纯framework模式无法自动关联这些依赖
  • 确保GitLive SDK版本与原生Firebase Pod版本兼容,版本不匹配会导致链接错误

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 20:34:54