Realm.io build errors when using cocoapods `use_frameworks!` - ios

Goal: Be able to use swift pods in an ObjC project
Steps Taken:
Altered Podfile by appending use_frameworks!
Ran pod install (Cocoapods version 1.0.0)
Built workspace again
Result (Errors):
I get the following Realm.io errors (pod installed from pod 'Realm' since I'm coding in ObjC):
RLMRealm.h:51:1: Duplicate interface definition for class 'RLMRealm'
RLMRealm.h:95:62: Property has a previous declaration
RLMRealm.h:105:38: Property has a previous declaration
RLMRealm.h:110:56: Property has a previous declaration
RLMRealm.h:115:38: Property has a previous declaration
RLMRealm.h:297:28: Property has a previous declaration
RLMRealm.h:493:1: Duplicate interface definition for class 'RLMNotificationToken'
Problem-Solving Steps Taken:
(Previous ones in edit history that led to this simplified question)
Deleted all pods and reinstalled (no effect)
Unlinked Pods framework in Build Phases and relinked (no effect)
Cleaned and built / Cleaned build folder and built (no effect)
Tried importing with "", <>, and #import (currently all imports in my code are done with #import <Realm/Realm.h>) (searched with #import <Realm and #import "Realm) (no effect)
Created new project, copied files over, and pod installed (no effect)
Searched project folder for "#interface RLMNotificationToken" and only found one instance of the RLMRealm.h file, so I don't have duplicates
Deleting all of my files except for AppDelegate.h/m builds successfully
Searched for #import "R, #import <R, #import R and found a rogue #import <RLMRealm.h>
Questions:
I'm frankly really confused and not sure what to do at this point.
So how do I fix these build errors? Why is this happening? Or what other problem-solving steps should I try? (Answers to any of these questions would be appreciated)

Evidently one of my files had a #import <RLMRealm.h> in it (not sure how that got in there). I changed that to #import Realm; and it all works now. I missed that when searching before and only found it while combing my code. Interesting that it works with the library but not with the framework. Well, figured it out and it's all good now.

Realm pod for swift is "RealmSwift". I think you are using objective-c pod.
Have a look at this link Realm for Swift. You can also drag and drop realm framework, this will save from errors you have been facing.

Please check all places, where you import Realm classes. In my case I imported #import <RLMArray.h>. Should be #import <Realm/RLMArray.h>

Related

How to fix this'FIRApp' has different definitions in different modules; first difference is defined here found property?

Could not build module 'Firabase'
Problem
I tried to update GoogleMobileSdk. I deleted Subfile.lock, the Pods folder and then added to Subfile - under 'Google-Mobile-Ads-SDK' I had a problem that it didn't detect #import GoogleMobileAds ;, but I did drag-and-drop and it worked, but another came out error. The one I showed in the photo above that there is a problem with Firebase

Modules are disabled - but why?

I'm struggeling with Modules in a project. Where I use #import I get "Use of '#import' when modules are disabled". But why are they disabled?
In my build settings I have "Enable modules (C and Objective-C)" set to Yes for all targets.
Setting "Link Frameworks Automatically" to Yes or No does not impact this (compile-time) error
Although the project used to have Objective-C++ and some C++ code, it doesn't anymore. Are there any project-settings I can have missed that were set because of this?
I have no more .pch files in the project, and the build settings have no mention of them
I use CocoaPods (0.39.0) with "use_frameworks!" and the modules I wish #import are from there. But the same error happens if I replace the '#import ' or '#import ' with '#import Foundation;' and '#import UIKit', so I expect this is not related
The project is from pre-iOS7 so I might have missed a setting that used to be on by default
The project requires iOS 8 and builds against iOS 9.2.
I realize that loading third-party modules will probably slow down the apps loading time. I'm converting to CocoaPods with use_frameworks! so that I can measure by how much. If it's not too bad, I'd like to use as I'm planning to move multiple swift-only parts of the codebase into their own frameworks (as open source coocapods)
I believe that this is not be a duplicate of other questions on SO since I've gone through the ones I found (big thank-you to this one), followed the links, re-watched WWDC'13 session 404, and read the related posts on Apples forums, so I believe I've done my homework. :-)
In my project I have a bridging header to bridge from ObjC to Swift, and there is a generated header file to bridge from Swift to ObjC. It turns out that if the bridging header referenced headers where the implementation file referenced the bridge file from Swift to ObjC, module support is disabled. So be careful about what you put in your bridging file, and be careful about when you import the generated -Swift.h file.
Firstly go to the terminal and type xcode-select -p. It should say, /Applications/Xcode.app/Contents/Developer. If it doesn't, then type, sudo xcode-select -s /Applications/Xcode.app and hit enter and type in your password.
If that doesn't fix it, try deleting your project's derived data directory. Go to the Projects view and delete the derived data for your project. Then clean your build folder (command-shift-K). Run Analyze (command-shift-B) and resolve any issues in blue and yellow.
Now if #import is still not working, create a brand new XCode project. Verify that #import works in it. If it doesn't, then your XCode installation got screwed up probably, or your HDD is dying. Delete XCode and re-download it, see if that works. Restart into the recovery partition and see if you have some disk issues (unlikely, but hey).
If #import works in the new project, try taking all your from your current project and copying them into the new project. Make sure you have the latest version of cocoapods and then freshly install your pods into the new project.
If all of that doesn't fix it, you probably left an #end statement out somewhere or have a missing } ...

Swift 'Could not build Obj-C module 'BranchInvite'

I've been following the instructions for implementing this SDK: https://github.com/BranchMetrics/Branch-iOS-Invite-SDK... below is what I have in my Podfile:
platform :ios, '8.0'
use_frameworks!
target 'My-App' do
pod 'BranchInvite'
end
And here is the error I'm getting...
I've done a lot of troubleshooting to try and figure out the problem, looked at past issues of this reporsitory of this sort, and for some reason I cannot get "BranchWelcomeViewController" (nor BranchInvite) to be recognized/imported. Any idea what I'm doing wrong here? Do I need to populate my bridging-header?
PS: I'm using Xcode 7, Swift 2, OS X 10.10.5, and the latest version of Cocoapods.
Thanks
#SamYoungNY, after debugging using the project you sent over, the best approach using Swift appears to be the following:
Podfile
pod "Branch"
pod "BranchInvite"
your app's bridging header
#import <Branch/Branch.h>
#import <BranchInvite/BranchInvite.h>
#import <BranchInvite/BranchInviteViewController.h>
#import <BranchInvite/BranchInviteTextContactProvider.h>
#import <BranchInvite/BranchInviteEmailContactProvider.h>
#import <BranchInvite/BranchWelcomeView.h>
#import <BranchInvite/BranchWelcomeViewController.h>
#import <BranchInvite/BranchWelcomeControllerDelegate.h>
#import <BranchInvite/BranchWelcomeDefaultView.h>
Then be sure to use your project's .xcworkspace file if you weren't previously. Please let us know if this doesn't work. I'm happy to continue to debug with the actual project you sent over.
I received a lot of help from #st.derrick on this question, and there was something wonky with my version control but in the end I got it working with something I found in the branch.io documentation, the answer is in this link:
https://support.branch.io/support/discussions/topics/6000008855
I can't comment yet but here's the archived text from that thread SamYoungNY linked to.
If you're running into an issue where you know that you've imported >Branch, but Xcode can't seem to find it, we may know the answer. You're >probably seeing a screenshot like the one below:
(Picture not archived)
This likely means that you are importing Branch as a "folder reference" >and not a "group".
Delete the Branch folder from your project
Make sure Branch is no longer in your project's folder (in the file >system, not Xcode)
Re-import Branch and be sure to select "Create Groups" (see screenshot >below)

Google/Analytics.h file not found when adding to AppDelegate

I am trying to integrate Google Analytics in my ios project using Cocoapods. However, after following this for the steps till adding configuration file to my project, when importing the Google/Analytics.h in AppDelegate I get error for file not found. Tried following things:
Added $(SRCROOT)/Pods/GoogleAnalytics to User Header Search Paths in Build Settings.
Added libGoogleAnalyticsServices.a to link binary with libraries in build phases.
Added -lGoogleAnalyticsServices in Other Linker Flags.
Don't really want to do 2 and 3 as they make it free from Cocoapods.
What exactly am I missing?
Swift 3
With version 3.17.0 (installed using pod 'GoogleAnalytics' in Podfile):
Open yourproject.xcworkspace instead of yourproject.xcodeproj
Use #import <GoogleAnalytics/GAI.h> in the bridging header file
Edit:
Per jeremy piednoel's comment you may also need
#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>
Problems
The code examples on the official documentation suggest
installing 1.0.0. Which doesn't even have binaries compiled for
arm64.
There seem to be at least three separate pods related to
GA. GoogleAnalytics-iOS-SDK, GoogleAnalytics, Google/Analytics.
Solution
Add this to your Podfile: pod 'Google/Analytics' and then pod install.
That should work. Now you can simply import Google/Analytics.h as suggested in the docs:
#import <Google/Analytics.h>
Further Discussion
There were two sets of issues that I ran into:
When using the incorrect suggested pod version (1.0.0), was a 64-bit compatibility issue. (ld: symbol(s) not found for architecture arm64)
When using the other pods (GoogleAnalytics-iOS-SDK and GoogleAnalytics) I had complaints of a missing <Google/Analytics.h> header file. ("Google/Analytics.h" not found)
I found this gentleman's post on a mailing list which suggested the Google/Analytics pod with no version number. (pod 'Google/Analytics' as noted above.)
This is a bug in cocoapods.
you need to add $(SRCROOT)/Pods/Google and $(SRCROOT)/Pods/GoogleAnalytics with recursive option to your User Header Search Paths.
Then include the #import "Analytics.h" instead of #import
When you add $(SRCROOT)/Pods/GoogleAnalytics to User Header Search Paths in Build Settings, also select recursive option. It will allow your project to search in GoogleAnalytics and all of its sub-directories.
UPDATED:
I have tried the tutorial and it works fine without any extra step. My pod version is 0.35.0. When you create configuration file, remember to enable GoogleAnalytics service.
UPDATED:
As #RajatTalwar pointed out, you also need to add $(SRCROOT)/Pods/Google with recursive option. Then include the #import "Analytics.h" instead of #import
If anyone else out there is having an error with trying to #import <Google/Analytics.h>, and the other solutions online aren't helping you, you should read on.
I was having this problem and none of the solutions I found would fix it. Then I noticed that one of my targets worked while the other one did not (I had two in the same project), and I tried to track down what was the difference between the two targets.
I noticed that there was a difference in the project on the General tab under Deployment info, where the second target (the one which worked) had separate options for iPhone and iPad, but the first did not. Someone else online said that they received these two new options when they duplicated their target. My second target was also a duplicate of the first, originally.
To make a long story short, I found that if I duplicated my target that the duplicate now suddenly worked. Those separate iPhone and iPad options also magically appeared. So I guess my project target was non-standard and causing a problem, probably because this project was created a long time ago.
I then just deleted the original target and renamed the new one to be the same name, although there was some cleanup work required in the build settings related to the plist file (it made a copy.plist file).
Hope this helps someone.
Check if you have multiple targets, in this case add pod 'Google/Analytics' foreach target in you pod file:
def google_pods
pod 'Google/Analytics'
end
target 'target 1' do
google_pods
end
target 'target 2' do
google_pods
end
target 'target N' do
google_pods
end
Also my $0.02 to this, since it seems to be a never ending story. None of the suggestions above did help. I got this obscure message from pod install
[!] The `blabla [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-blabla/Pods-blabla.release.xcconfig'. This can lead to problems with the CocoaPods installation
Finally I inspected my project.pxbprojand found, that I had this entry:
HEADER_SEARCH_PATHS = "";`
Obviously this is treated as "defined", so I changed it to
HEADER_SEARCH_PATHS = "$(inherited)";
and boom - all the Google suggested includes work
#import <GoogleAnalytics/GAI.h>
#import <GoogleAnalytics/GAIDictionaryBuilder.h>
#import <GoogleAnalytics/GAIFields.h>
Run pod update
Clean Build Files
Run Project
remove valid archs from build settings

Including Google Analytics in Swift Bridging Header

This has actually been driving me crazy.
I've been following the instructions on the Google Developer's site (which doesn't actually have an import line, but if you inspect the element you can kinda notice that someone messed up and it's supposed to be #import <Google/Analytics.h>)
But Xcode just refuses to find the Google Analytics, while it imports the other header in my bridging header perfectly alright (e.g. it reads the file fine, but only does one of the imports).
My file looks like this:
#import <workinglibrary.h>
#import <Google/Analytics.h> // this doesn't work!
I've tried every variation of <Analytics.h> or "Google/Analytics.h" and so on. My header search paths looks fine too:
"${PODS_ROOT}/Headers/Public/Google"
"${PODS_ROOT}/Headers/Public/Google/Google"
"${PODS_ROOT}/Headers/Public/GoogleAnalytics"
...
Final caveat: I'm not sure (since Xcode doesn't fully build when I do this), but I think that Xcode properly imports the Analytics.h file if I comment out the #import <workinglibrary.h> statement (at least, I can Apple + Click analytics functions in other files to get to their declaration).
EDIT: just kidding that last bit isn't true
I had same issue. This has been fixed in cocoapods 0.38.2
To update use: gem install cocoapods
You can use_frameworks!
Seems like for the latest stable Swift/XCode/Cocoapods/GA it needs putting #import <GoogleAnalytics/GAI.h> into bridging header

Resources