Error "dyld: Library not loaded: @rpath/XCTest.framework/XCTest" displays When deploying WebDriverAgent into real device

Thanks so much for your detailed explanation. I have to switch focus for a day or two, but I’ll get back to you and update this post after I’ve reviewed my configurations.

Did you ever resolve your issue.

I think I ran into the one you were facing, and I think it was caused because Carthage was already installed on my machine in a different location. It messed up everything.

DD

@dduphorn - I haven’t resolved my issue yet because work is pulling me in a different direction. I do want to get back on this and get it resolved though.

Do your Appium server logs tell you that Carthage is found? I’m asking because while I was working on this, I know I ended up with multiple installations of Carthage and I was wondering whether that would be a problem. According to the logs Carthage was found, so I figured it wasn’t an issue.

Thanks for the follow-up. I’ll get back on this as soon as I can.

@chiwhitesox56

I did not see anything in the logs, but I did notice the appium-xcuitest-driver was getting installed in a different director.

When Carthage was not installed appium-xcuitest-driver appeared in the following directory.

/Users/[User]/.nvm/versions/node/v6.0.0/lib/node_modules/appium/node_modules/appium-xcuitest-driver

When Carthage was previously install it appeared

/Users/mpsadmin/node_modules/appium-xcuitest-driver

I might of missed a step, but when it appeared in the 2nd one it messed everything up.

DD

Hey @dduphorn - Thanks so much for your patience. I finally have time to work on this again.

It looks like I also have two different instances of appium-xcuitest-driver in my file system, though I don’t know if the appearance of either had anything to do with the installation of Carthage:

instance A:
/Users/[User]/.nvm/versions/node/v7.3.0/lib/node_modules/appium/node_modules/appium-xcuitest-driver

instance B:
/Users/[User]/node_modules/appium-xcuitest-driver

Loos like exactly like what you posted… Can you tell me what you ended up doing about the second installation when you realized that it was messing things up? Also, when you run Appium Doctor, where is it finding Carthage? For me it’s at: /usr/local/bin/carthage

@chiwhitesox56

Appium Doctor
/Users/[User]/.nvm/versions/node/v6.0.0/bin/carthage

What is the current error you are getting? I remember copying some file from one Carthage directory to another.

Thanks

DD

@dduphorn - I’m going to have to get back you you once again about the error that I’m having.

I sat down today with the iOS developer because I was getting an error related to the Provisioning Profile. (This was on a device that I had not used before. I didn’t get this error on the device that I’ve been using to try to resolve this issue.) After an hour or two of troubleshooting, we noticed that my login keychain had disappeared. It then returned, but only temporarily. Not really sure what’s going on, but I’m in the process of backing everything up. I’m going to reformat my machine tomorrow and try this from scratch. I noticed this a few weeks ago but I thought it had been resolved.

I’ll keep you posted once I try again. Thanks again for your responsiveness and willingness to help.

@dduphorn

Hello again. I wiped my entire machine, started over, and I think I’m very, very close to getting this working.

I followed the steps on the github for appium-xcuitest-driver: https://github.com/appium/appium-xcuitest-driver/blob/master/docs/real-device-config.md

For the certification, I followed the steps shown in this video: https://www.youtube.com/watch?v=Yi177Si5aLU

After completing all of the steps, I ran the following command as advised in the github readme to verify that everything worked:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=<udid>' test

As you can see in the screen capture below, my output matches the output that one is supposed to see if everything was set up correctly:

Despite the success with the xcodebuild, I’m still getting an error when I try to run my tests on the device. Below is the link to the gist, followed by the two main errors that I’m seeing in the logs:
https://gist.github.com/ChiWhiteSox56/e45376a51eb870601afc6c1c7a6a762e

[debug] [XCUITest] Error checking install status: Command ‘ios-deploy --exists --id 85460f322cff23dfdb2f5b94504b0fd64f8ef712 --bundle_id com.kaplan.atom.spark’ exited with code 255

[XCUITest] Error: Could not install app Command 'ios-deploy --id 85460f322cff23dfdb2f5b94504b0fd64f8ef712 --uninstall --bundle /var/folders/92/2p4l0l3n0bq3nqjvxs_j6xcw0000gn/T/201729-38886-b6ctvy.g81kwvzpvi/Payload/Atom.Squirrel.iOS.app’ exited with code 253
at IOSDeploy.install$ (…/…/lib/ios-deploy.js:39:13)
at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)

These errors do not tell me a whole lot, so I tried installing the app to my device from the command line to see if I could figure out what the problem is. I got the following error:

[ 70%] VerifyingApplication
2017-03-10 14:13:05.431 ios-deploy[43080:4434580] [ !! ] Error 0xe8008015: A valid provisioning profile for this executable was not found. AMDeviceSecureInstallApplication(0, device, url, options, install_callback, 0)

If I use the path / bundle ID for the Integration App in my tests, I can launch the app on a real device! I just need to figure out what I need to do to make this work with the .ipa that I need to test. (Admittedly, I’m struggling with the concept of provisioning profiles.) Hopefully I can figure this out but if not, it probably belongs in a new or different thread since this is no longer about the “dyld: Library not loaded” error.

Again, thanks so much for your help.

Deleted This post because the fix was for a different issue

which ios-deploy returns /usr/local/bin/ios-deploy, and /usr/local/bin/ is already in my PATH.

which ios-deploy
/Users/[user]/.nvm/versions/node/v6.0.0/bin/ios-deploy

Maybe navigate to that director and brew install ios-deploy

Did that work?

After I wiped my machine I didn’t reinstall nvm, so I no longer have that directory. Just trying to keep things as simple as possible. I did notice that if I run which ios-deploy I get the following: /usr/local/bin/ios-deploy, but ios-deploy can also be found at /usr/local/lib/node_modules/ios-deploy/build/Release/ios-deploy. This is where the ios-deply executable is.

/usr/local/bin/ios-deploy:

/usr/local/lib/node_modules/ios-deploy/build/Release/ios-deploy:

I talked to the developer and he had been giving me Release builds for testing on the real device. I requested and received a development/debug build, and I get similar results: Installation fails at 70%. However, the error message is a little bit different:

[ 70%] VerifyingApplication

2017-03-13 16:17:11.628 ios-deploy[52734:6571616] [ !! ] Error 0xe8008014: The executable contains an invalid signature. AMDeviceSecureInstallApplication(0, device, url, options, install_callback, 0)

I can’t tell if the problem is with the certification? ios-deploy? Both? I did install ios-deploy with brew, if that helps. Thanks again for your help.

Edit: I also tried reinstalling ios-deploy in the location that it was originally installed in. That did not work.

Can you try installing this app onto the device with Xcode? I’d like to see the error if not.

Xcode -> Window -> Devices -> “plus sign” under Installed Apps

.ipa with dev certificate:

.ipa with distribution certificate:

My understanding is that we want to use the developer build here, but I figured I’d try both just in case. Admittedly, I’m still trying to wrap my mind around the certification and provisioning profiles. Never needed those to run tests before XCUITest replaced UIAutomation. This is the first I’m seeing of an error about an application bundle though, so maybe that’s the problem?

Thanks for your help.

@dduphorn, @wreed

After 5 months of dealing with this, I can finally run iOS tests on a real device!!! I’ll update when I understand exactly why this worked, but the developer and I did some troubleshooting and it turns out that I actually needed an .app file rather than an .ipa. I can’t believe it finally works.

Thanks again for your help and like I said, when I understand this better I’ll post an explanation so others can benefit from it.

Codesigning can be a serious obstacle, and the tools needed to verify an ipa or app file are not always obvious. I’m glad this worked for you.

1 Like

@chiwhitesox56
what was the problem? how did you solve this problem?
I am totally stuck in the great mythology of signing and can’t figure out whats wrong.
actually I get the “Library not loaded: @rpath/XCTest.framework/XCTest” error

@derunewige

I was stuck for 5 months, unable to run tests on real iOS devices. I wish I could point you to one exact configuration or error that was causing this framework/XCTest issue (and many other issues), but I cannot. What I ended up doing is wiping my whole machine and starting the setup process from scratch. It was a gamble because I really didn’t know what I was going to do if that didn’t work, but it did.

While in the process of setting up my environment, I took very detailed notes of exactly what I did, in order. I’ll share this with you. There are some very basic steps in here (i.e. install Chrome, etc.) but I wanted a record of exactly what I did in case I had problems again:

  1. Install Chrome / Firefox
  2. Install Xcode
  3. Install Xcode command line tools (xcode-select --install)
  4. Install Homebrew (ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)")
  5. Install Appium GUI // **NOTE: This is obsolete; install Appium Desktop instead
  6. Install JDK (JDK 8 Update 121) // **NOTE: Not sure what the current version is, but this was most recent at the time
  7. Install Eclipse (Eclipse IDE for Java Developers) NOTE: I recently switched to Intelli-J. Personal preference.
  8. Install git (brew install git)
  1. Install node with brew (brew install node) //** NOTE: I initially installed nodejs from https://nodejs.org/en/, but I later read that it shouls be installed via brew. If you installed from the site and need to uninstall and reinstall with brew, instructions are here
  2. Add export PATH="/usr/local/bin:$PATH" to bash_profile
  3. Run sudo npm install npm -g to make sure that I got the most recent version of npm
  4. Install Appium (npm install -g [email protected])
  5. Install TestNG in Eclipse (Help -> Eclipse Marketplace)
  6. Install ideviceinstaller (brew install --HEAD ideviceinstaller)
  7. Install appium doctor (npm install appium-doctor -g)
  8. Install Carthage (brew install carthage)

At this point, you should be able to run tests on the Simulator

  1. Install ios-deploy (brew install ios-deploy)
  2. Install appium-xcuitest-driver (npm install -g appium-xcuitest-driver)
  3. Install deviceconsole (npm install -g deviceconsole)
  4. Navigate to /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent and run the following:
    mkdir -p Resources/WebDriverAgent.bundle
    ./Scripts/bootstrap.sh -d
  5. Follow the steps in this video: https://www.youtube.com/watch?v=Yi177Si5aLU (You will have completed some of the steps in this video already, but the main takeaway is the Xcode part - getting rid of errors in WebDriverAgent.xcodeproj, code signing, etc.)
  6. In the WebDriverAgent folder, run bash Scripts/bootstrap.sh -d
  7. Make sure app and developer account are trusted on device (Settings -> General -> Profiles & Device Management)

At this point, you should be able to run tests on real iOS devices

I had an awful time with this and maybe there’s a better way to do it, but this is what finally got me up and running. I wish I knew what was causing this framework/XCTest problem but I never figured it out. Best of luck to you, and if it doesn’t work I’d be happy to help you troubleshoot.

2 Likes

Thanks a lot!!!
It is really helpful to have your list where everything you have to do is at one place and you do not have to search at many different pages.

I did the same as in the youtube vid and it still didn’t work.
But then i deleted all apple certificates from the keychain and deleted the user from xcode. rebooted the computer. and added the user. Short check that the signing and bundle ids are right and then it WORKED!
So maybe some kind of corrupted certificate or anything related could have caused this problem =)

1 Like

@derunewige

I’m so glad that you got it working! Being stuck is the worst… So frustrating. It took me a while to understand how to deal with the various certification issues that can come up, but I think I have a pretty good grasp of it now.