簡體   English   中英

多目標項目中的 GoogleService-Info.plist

[英]GoogleService-Info.plist in a multi-target project

我有一個 firebase 應用程序,它使用多個模塊,因此無需啟動模擬器實例即可運行測試。

我已將我的項目分解為多個 spm 目標,因此我的文件夾結構類似於以下內容:

MyApp
--- App
------ iOS
--------- ContentView.swift
--------- GoogleService-Info.plist
--- Sources
------ FirebaseClient
--------- FirebaseClient.swift
--- Tests
----- FirebaseClientTests
--------- FirebaseClientTests.swift
--- Package.swift

FirebaseClient.swift調用FirebaseApp.configure()有效,但前提是主應用程序正在運行。 如果我嘗試從FirebaseClientTests.swift調用FirebaseClient.swift中的設置 function,我會收到 plist not found 錯誤。 但是,如果我在 FirebaseClient 中創建資源文件夾,則它無法在任一可執行文件中找到 plist。 如何設置項目以便目標和測試都能找到 GoogleService-Info.plist?

每個測試都使用單獨的包標識符運行,因此不可能共享GoogleService-Info.plist s。 您需要從 firebase 為您的測試創建一個新的GoogleService-Info.plist (測試的包 ID 將只是FirebaseClientTests )。 獲取測試包 ID 並將其放入 FirestoreClient 的資源文件夾中。 如果您沒有資源文件夾,請將 FirestoreClient 的文件夾結構修改為類似於以下內容:

--- Sources
------ FirebaseClient
--------- Resources
------------ GoogleService-Info.plist
--------- FirebaseClient.swift

並將 Package.swift 中的目標定義更改為以下內容:

.target(
   name: "FirestoreClient",
   //    ...
   resources: [
      .process("Resources"),
   ]
),

最后,您必須告訴 Firebase 在調用FirebaseApp.configure時不要在主包中查找 plist。 使用此答案中的解決方案 - 只需將Bundle.main替換為Bundle.module

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM