Xcode 10 - UITests - Reason: image not found - ios

I'm trying to run the UITests for my App but it's crashing as soon as it loads. Here's the error.
2018-09-29 16:19:49.577151+1000 xxxUITests-Runner[6007:69633] (dlopen_preflight(/Users/Acc/Library/Developer/Xcode/DerivedData/xxx-bjuwemcifadxhlhgojgfktmmades/Build/Products/Debug-iphonesimulator/xxxUITests-Runner.app/PlugIns/xxxUITests.xctest/xxxUITests): Library not loaded: #rpath/libswiftContacts.dylib
Referenced from: /Users/Acc/Library/Developer/Xcode/DerivedData/xxx-bjuwemcifadxhlhgojgfktmmades/Build/Products/Debug-iphonesimulator/xxxUITests-Runner.app/PlugIns/xxxUITests.xctest/Frameworks/MapboxGeocoder.framework/MapboxGeocoder
Reason: image not found)
I'm using CocoaPods (v1.6.0.beta.1) to install my frameworks. I'm running Xcode 10 with Swift 4.2 and iOS 12. Also, Git is used as version control with other developers (Perhaps there're conflicts?).
My target app works perfectly, both on a simulator and a real phone, and so does my unit tests. But my UITest target fails as soon as it launches up. This problem happens on both a simulator and a real machine.
There have been many posts on the issue before, but none of them have helped me so far. I've had 2 isolated occurrences before, the first time I've solved by adding dependencies into my pod file for the UITest unit, and the second time by simply removing my target and copy & pasting the classes back into the new target (unconstructive, but last resort). I can do the same this time as well but it's a bit of a waste of time and I'm afraid that this will crop up again in the future.
This is what I've done so far:
Clean Xcode builds folder and deleted derived data, IOS device logs, and User Data folders.
Restarted Xcode, Mac, as well as my device and simulators, and recloned repository, and pod update && pod install
Have 'Always embed swift standard libraries' as yes
Checked my Target Application is correct
Made sure offending framework (MapboxGeocoder.framework) is included in Embed Pod Frameworks

So after 5 days, I managed to solve my own problem.
I solved it by moving my UITests target out of the scope of my main app in Podfile.
From:
target 'App' do
use_frameworks!
pods 'Firebase'
target 'AppUITests' do
pods 'Testingpod'
end
end
To:
target 'App' do
use_frameworks!
pods 'Firebase'
end
target 'AppUITests' do
pods 'Testingpod'
end

Has found another solution suggested in Cocoapods issue.
As my project is a framework, so the test does not have a host application.
Changed Podfile
target 'framework' do
use_ frameworks!
pods my_dependencies
target 'framework_tests' do
inherit! :search_paths
end
end
To
target 'framework' do
use_ frameworks!
pods my_dependencies
target 'framework_tests'
end
https://github.com/CocoaPods/CocoaPods/issues/8139

Related

Move from manual install to use Realm through Cocoapods in Xcode

I’m currently using Realm in one of my projects, where I manually installed it. Everything was working fine until I updated Xcode from 10.1 to 10.2. Now I keep getting the following error.
Module compiled with Swift 4.2 cannot be imported by the Swift 5.0 compiler: /Users/userName/MyApp/RealmSwift.framework/Modules/RealmSwift.swiftmodule/i386.swiftmodule
I believe this has to do with the fact that when I try to replace the Realm frameworks in my project with the newest Realm compiled for Xcode 10.2, Xcode doesn’t copy the files, it just references them even when having the Copy Files If Needed option checked.
Anyways, I now would like to try using Realm through Cocoapods to eliminate this kind of issues every time I update Xcode, so my questions are…
What do I need to change in Xcode in order for me to move from manual install to use Realm through Cocoapods?
What do I need in Framework Search Paths?
Do I need to remove the Run Script Phase
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh"?
What do I need in my Pod file? I’m more interested to see how I would incorporate Realm for my WatchApp Extension since I couldn’t find any info in the documentation.
Here is how my Pod file looks like right now.
Pod File
#platform :ios, '9.3'
target 'MyApp' do
use_frameworks!
# Pods for MyApp
pod 'Firebase/Core'
pod 'NVActivityIndicatorView'
target 'MyAppTests' do
inherit! :search_paths
end
target 'MyAppUITests' do
inherit! :search_paths
end
end
target 'MyApp Watch App' do
use_frameworks!
end
target 'MyApp Watch App Extension' do
use_frameworks!
end
FYI - I’m already using Cocoapods in my project but not for Realm yet. Also, I’m using Realm for iOS and WatchApp Extension in this project.
If you already have the workspace created by cocoapods, you don't need to modify your project settings, when you add a new pod to your podfile, cocoapods will automatically handle linking that to your project correctly.
Simply remove the manually added Realm framework files, remove the custom Run Script build phase containing "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Realm.framework/strip-frameworks.sh", then run pod update and you should be good to go.
As for the original issue of
Module compiled with Swift 4.2 cannot be imported by the Swift 5.0 compiler: /Users/userName/MyApp/RealmSwift.framework/Modules/RealmSwift.swiftmodule/i386.swiftmodule
, when using precompiled frameworks, you need to wait until the developer of the framework updates the precompiled versions for Swift 5 (or the newest version you want to switch your project to) before you can use them.
Since cocoapods compiles all dependencies from source on your own machine, this issue of incompatible Swift compiler versions cannot arise and you can even control which Swift version to use for each project specifically from your podfile.

Xcode 10.1: Pods not compiling when running UITest

I am trying to implement UITests in an application I'm working on.
When I am in my UITests.swift file and I try to run the app from a test, Xcode gives the following error for some of the pods I'm using:
Command CompileSwift failed with a nonzero exit code
It gives this error for a bunch of pods that are compiling just fine when running the regular project:
My PodFile looks as follows:
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
source 'https://github.com/cocoapods/specs.git'
project 'Project.xcodeproj'
use_frameworks!
# Define all thirdparty pods we need
def thirdparty
pod 'Moya', '~> 11.0'
pod 'Alamofire'
pod 'SwiftyJSON'
pod 'Differ'
.. a bunch of other pods
end
# Pods for Project project
target 'Project' do
thirdparty
end
# Pods for ProjectTests
target 'ProjectUITests' do
thirdparty
pod 'Nimble'
end
I'm having a hard time reasoning why this is happening, as my project normally compiles just fine. Other posts on S.O. regarding this problem report that the problem also occurs when building the project rather than just running for a test
Question How can I make sure that all pods I use in my project, also compile correctly when building from a UITest?
How can I make sure that all pods I use in my project, also compile correctly when building from a UITest?
The only way to know whether something will build or not is to try to build it. So when you change your CocoaPods configuration, even if that's just to update to a newer version of one or more pods, you need to try building each target.
target 'ProjectUITests' do
thirdparty
pod 'Nimble'
end`
According to your Podfile, you've got the pod Nimble being used only in the ProjectUITests target. If that's the only target that fills to build, then it seems likely that that pod is the culprit.
Except for one case (at least as far as you've shown) your Podfile doesn't specify versions for the various pods that it specifies. If you leave out the version for a given pod, your project will use the latest available version. That means that anytime you update your pods you'll pull down the latest version, even if that new version contains breaking changes. It would be safer to specify the version that you know works, or at least to limit the version to minor version and patch updates, like:
pod 'Nimble', '~>7.0'
That will let CocoaPods automatically use the latest version up to but not including 8.0. If the pod developer properly follows the semantic versioning scheme, that should ensure that you don't inadvertently pull in any breaking changes.
The problem is that target :AppModuleTests do do not have an app host and you are using inherit! :search_paths. This means that this target would find the dependencies to load them from the host but in this case there is none.
target TestApp do
pods
target :AppModuleTests
end
This worked for me.

Can't archive react-native project in XCode for staging configuration with Pods

react-native: 0.50.3
xcode: 9.1 (9B55)
I have 3 configuration:
Default
Stage
Production
In 1 and 3 Product > Archive is working fine. When I try to archive Stage, I got an error:
ld: library not found for -lPods-carrier_mobile_app
This error appears after adding Pods in my project. Podfile looks like
platform :ios, '8.0'
target 'carrier_mobile_app' do
# Pods for carrier_mobile_app
pod 'RSKImageCropper'
pod 'QBImagePickerController'
end
I think I should configure Pods for Stage configuration correct. Any ideas?
Referring to this here: https://medium.com/#guyeldar/setting-up-multiple-build-configurations-for-your-xcode-project-c237265e8324
Theoretically adding $(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME) to your Header, Framework, and Library search paths in your targets will work. However, it only worked one time for me, then I accidentally changed something, and it hasn't been working since. Worth a shot, though.

Can't upload IOS app to iTunes with Xcode 7 and GoogleMaps with Podfile

I have an app that I've rebuilt using Xcode 7. This app has been using the GoogleMaps IOS SDK. At the same time (big mistake), that I was updating the code to Xcode 7 (for IOS 9 support), I decided to upgrade to the latest version of the GoogleMaps API. This version requires that the project use Podfiles.
I have multiple targets and getting Podfiles to work was a pain, but I got it to work. The app compiles and runs fine in the simulator. The problem comes when I archive the project and try to upload the app to the App Store. I get the following error:
I'm not sure what to do. I can't seem to find any information on this error. Here is a copy of my Podfile:
# Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, ‘7.0’
# Common Pods
def common_pods
pod 'GoogleMaps'
end
# Target List
target 'app1' do
common_pods
end
target 'app2' do
common_pods
end
target 'app3' do
common_pods
end
Since I don't control the Google API, I can't change their Info.plist file. Am I missing something?
After a lot of research, I've concluded that this is in fact a bug with the GoogleMaps API for IOS when compiled using Pods and Xcode 7.
The problem is that the info.plist file under 2 different packages has an illegal value. The solution is to remove that illegal value. This is a pain to do manually. I found a person that had a partial solution. I've expanded their solution to encompass both plist files.
The solution is to add the following code to the end of your Podfile:
# Patch GoogleMaps' bundle to avoid iTunes connect submission error
post_install do |installer|
`/usr/libexec/PlistBuddy -c "Delete :CFBundleSupportedPlatforms" ./Pods/GoogleMaps/Frameworks/GoogleMaps.framework/Resources/GoogleMaps.bundle/Info.plist`
`/usr/libexec/PlistBuddy -c "Delete :CFBundleSupportedPlatforms" ./Pods/GoogleMaps/Frameworks/GoogleMaps.framework/Resources/GoogleMaps.bundle/GMSCoreResources.bundle/Info.plist`
end
This code deletes the illegal values from the plist files and works in both the simulator and on physical devices. Once archived with this new script, the app can be submitted to iTunes without issue.
Hope this helps.

Cocoapods Completely Broke

To start: I'm using Cocoapods 0.37.2, XCode 6.3.1 compiling for iOS 8.3
My project worked just fine before I ran a basic "pod update" now it's completely refusing to compile. I'm quite positive this has nothing to do with the pods themselves. Specifically the error I'm getting is this:
ld: warning: directory not found for option '-F/Users/user_name/Library/Developer/Xcode/DerivedData/AppName-bjozswzeepmhacfkeimeepxzcxgb/Build/Products/Debug-iphoneos/include'
ld: library not found for -lPods-AppName-AFNetworking
Podfile is this:
# Uncomment this line to define a global platform for your project
platform :ios, "8.0"
def shared_pods
pod 'SocketRocket'
pod 'AFNetworking'
pod 'DateTools'
pod 'Spotify-iOS-SDK'
end
target "AppName" do
shared_pods
end
target "AppNameTests" do
shared_pods
end
I have cleared DerivedData (many many times), cleaned my builds, restarted XCode, restarted my machine, I have ensured my config files and linker config lists are set up correctly. I've been using Cocoapods for years and never had this much trouble.
Completely frustrated and confused... questioning sanity.
Any help?
Information from CocoaPods troubleshooting doc. Hope this helps you.
If Xcode complains when linking, e.g. Library not found for -lPods, it
doesn't detect the implicit dependencies:
Go to Product > Edit Scheme
Click on Build
Add the Pods static
library, and make sure it's at the top of the list
Clean and build again
If that doesn't work, verify that the source for the spec you
are trying to include has been pulled from GitHub. Do this by looking
in /Pods/. If it
is empty (it should not be), verify that the
~/.cocoapods/master//.podspec has the correct git hub url
in it.
If still doesn't work, check your Xcode build locations
settings. Go to Preferences -> Locations -> Derived Data -> Advanced
and set build location to "Relative to Workspace".

Resources