@@ -75,7 +75,7 @@ extension CarthageUtils {
7575 /// Generates all required files for a Carthage release.
7676 ///
7777 /// - Parameters:
78- /// - packagedDir: The packaged directory assembled for Carthage and Zip distribution.
78+ /// - packagedDir: The packaged directory assembled for the Carthage distribution.
7979 /// - templateDir: The template project directory, contains the dummy Firebase library.
8080 /// - jsonDir: Location of directory containing all JSON Carthage manifests.
8181 /// - firebaseVersion: The version of the Firebase pod.
@@ -87,6 +87,7 @@ extension CarthageUtils {
8787 jsonDir: URL ,
8888 artifacts: ZipBuilder . ReleaseArtifacts ,
8989 outputDir: URL ) {
90+ factorProtobuf ( inPackagedDir: packagedDir)
9091 let directories : [ String ]
9192 do {
9293 directories = try FileManager . default. contentsOfDirectory ( atPath: packagedDir. path)
@@ -190,6 +191,44 @@ extension CarthageUtils {
190191 }
191192 }
192193
194+ /// Factor Protobuf into a separate Carthage distribution to avoid Carthage install issues
195+ /// trying to install the same framework from multiple bundles(#5276).
196+ ///
197+ /// - Parameters:
198+ /// - packagedDir: The packaged directory assembled for Carthage and Zip distribution.
199+
200+ private static func factorProtobuf( inPackagedDir packagedDir: URL ) {
201+ let directories : [ String ]
202+ let protobufDir = packagedDir. appendingPathComponent ( " FirebaseProtobuf " )
203+ do {
204+ directories = try FileManager . default. contentsOfDirectory ( atPath: packagedDir. path)
205+ } catch {
206+ fatalError ( " Could not get contents of Firebase directory to package Carthage build. \( error) " )
207+ }
208+ let fileManager = FileManager . default
209+ var didMove = false
210+ // Loop through each directory to see if it includes Protobuf.framework.
211+ for package in directories {
212+ let fullPath = packagedDir. appendingPathComponent ( package )
213+ . appendingPathComponent ( " Protobuf.framework " )
214+ if fileManager. fileExists ( atPath: fullPath. path) {
215+ if didMove == false {
216+ didMove = true
217+ do {
218+ try fileManager. createDirectory ( at: protobufDir, withIntermediateDirectories: true )
219+ try fileManager
220+ . moveItem ( at: fullPath, to: protobufDir. appendingPathComponent ( " Protobuf.framework " ) )
221+ } catch {
222+ fatalError ( " Failed to create Carthage protobuf directory at \( protobufDir) \( error) " )
223+ }
224+
225+ } else {
226+ fileManager. removeIfExists ( at: fullPath)
227+ }
228+ }
229+ }
230+ }
231+
193232 /// Creates a fake Firebase.framework to use the module for `import Firebase` compatibility.
194233 ///
195234 /// - Parameters:
0 commit comments