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

You got it working? That’s great!

I’m not getting an error in WebDriverAgent.xcodeproj at the moment. I was just going to see if I could help you if you were getting one.

After you updated the WebDriverAgentLib and the WebDriverAgentRunner signings did you created the Config.xcconfig file with the correct Development Team id?

If you did, did you try to clean and build a new App?

Below are the only Capabilities that I have set:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“newCommandTimeout”, 60 * 5);
capabilities.setCapability(“platformName”,“iOS”);
capabilities.setCapability(“deviceName”,strIOSDeviceName);
capabilities.setCapability(“fullReset”, true); //Not currently unistalling app
capabilities.setCapability(“automationName”,“XCUITest”);
capabilities.setCapability(“udid”,strIOSUdid);
capabilities.setCapability(“xcodeConfigFile”,"/Users/[user]/.nvm/versions/node/v6.0.0/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Config.xcconfig");
File f = new File(strIOSPath);
if(f.exists()) {capabilities.setCapability(“app”,strIOSPath);}
else{String strErrorMsg = “The IOS application path didn’t exists (”+strIOSPath+")";Reporter.log(""+strErrorMsg+"");Assert.fail(strErrorMsg);return null;}
capabilities.setCapability(“launchTimeout”, 60000);
capabilities.setCapability(“sendKeyStrategy”,“setValue”);

I don’t know what you did in step 2, and I didn’t do 4 & 5.

Based on the research that I’ve done and just by studying the content of the logs, I think this “Library not loaded” error is actually a code signing issue - especially since you didn’t have to make any changes to the XCTest.framework configuration in Xcode to get tests running on a real device

From terminal test log:

dyld: Library not loaded: @rpath/XCTest.framework/XCTest
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/DB1E8AF6-6C18-4B4A-9F6F-AA744148923F/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest: code signing blocked mmap() of ‘/private/var/containers/Bundle/Application/DB1E8AF6-6C18-4B4A-9F6F-AA744148923F/WebDriverAgentRunner-Runner.app/Frameworks/XCTest.framework/XCTest’

My Appium real device log shows the same error as above, but also includes " xcodebuild exited with code '65' and signal 'null'" which is indicative of a code signing issue.

A few questions for you, @dduphorn:

  1. The certificate that your private key is associated with - is it a Developer or a Distribution certificate?
  2. Am I understanding correctly from your capabilities that you did not set the following: realDeviceLogger, keychainPath, keychainPassword
  3. Does your development team ID match the ID listed next to the certificate in Keychain Access? (This may not apply if you’re not dealing with the keychain, but I thought that was required.)

For Step 2, I just meant that I made sure I had my real device selected as shown below. Sorry for the confusion there.

Thanks a lot for your help.

  1. The certificate that your private key is associated with - is it a Developer or a Distribution certificate? Answer Developer

  2. Am I understanding correctly from your capabilities that you did not set the following: realDeviceLogger, keychainPath, keychainPassword? Answer Correct

  3. Does your development team ID match the ID listed next to the certificate in Keychain Access? (This may not apply if you’re not dealing with the keychain, but I thought that was required.) ? The Developer gave me the team Id and I added it to my Config.xcconfig file which once created appears under the WebDriverAgent. When I click on the Config.xcconfig file make sure you have the Target Membership set to include WebDriverAgentLib & WebDriverAgentRunner.

  4. Yes, make sure you have the real device selected above

  5. Click Play and make sure Build Successful message appears

  6. Next open up your application project so you can clean and rebuild the app. Again make sure you select the real device.

Remember to add this to you capabilities
capabilities.setCapability(“xcodeConfigFile”,"/Users/[User]/.nvm/versions/node/v6.0.0/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/Config.xcconfig");

We will figure it out :slight_smile:

1 Like

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