Firebase Analytics with iOS framework development

2019-05-07 21:41发布

问题:

I am adding Firebase analytics using coocapods, my Podfile is

platform :ios, '8.0'
use_frameworks!

workspace 'ProjectWorkspace.xcworkspace'

abstract_target 'Shows' do
    pod 'SwiftProtobuf', git: 'https://github.com/apple/swift-protobuf.git', :tag => '0.9.24'
    pod 'Firebase/Core'
    pod 'Firebase/Messaging'

    target 'HostApp' do
        project 'HostAppFolder/HostApp.xcodeproj'

    end
    target 'HostAppReleaseTarget' do
        project 'HostAppFolderApp/HostApp.xcodeproj'

    end

    target 'FrameWorkProject' do
        project 'FrameworkProjectFolder/FrameWorkProject.xcodeproj'
    end

end

if I add SwiftProtobuf only as dependency it's working fine for host application as well as for Framework project.

If I add Firebase dependency, I get a run-time error and the application crashes with error msg

Class Foo is implemented in both, HostApplicationPath and FrameworkProjectPath One of the two will be used. Which one is undefined.

for each class file of Firebase.

when I remove other linker flags $(inherited) from framework project, it's work fine, but I can not use firebase into my framework project.

My framework and Host application is written in Swfit 3.0 and xcode version is 8.x

My Project structure is i have created a workspace manually and named it "EVAWorkspace.xcworkspace" and added my host application and framework project into this workspace and then i am adding cocoapods to workspace.

Eva is framework project and EvaApp is host application project.

回答1:

Before trying each of the following, use the "Clean Build Folder" option in XCode to ensure you're getting a clean build each time. If you want to be really sure, you can delete the DerivedData folder in ~/Library/Developer/Xcode before starting (just make sure Xcode is closed when you delete it)

First of all, ensure that your Pods project has "Build Active Architecture Only" set to NO in its Build settings. Then try cleaning the build folder and rebuilding. This might solve your issue, otherwise read on.

The most common reason for the problem you have described: "Undefined symbols for architecture X" is that you've imported a library in your code but have not linked against it correctly.

to solve this, you should either:

  • Add the library to "Linked Frameworks and Libraries" in your "BuildPhases"

  • Add the library's path to "Library Search Paths" under Build Settings, and then add `"-l{your library} to "Other Linker Flags".

If this does not solve your problem, it might be that the linker is not getting the required flags. You could try adding $(inherited) back to the "Other Linker Flags" section of Build Settings.

Don't forget to clean your build folder before trying each of these techniques.

If after doing all this your problem still persists, please delete all Cocoapods created files in your project and then post the output of pod install --verbose here.