iPhone Simulator problem – Corrupted Device

The system I inherited kicks off builds via Jenkins, so I saw this error in the Jenkins output

An error was encountered processing the command (code=146):
Unable to erase contents and settings in current state: Creating
10:40:48   355) Business-Cards samples Batch 15 Business-Cards sample 355: biz-card-martin_0128.JPG
10:40:48      Failure/Error: Appium::Driver.new(desired_caps).start_driver
10:40:48      Selenium::WebDriver::Error::WebDriverError:
10:40:48        Command failed: /bin/sh -c xcrun simctl erase 8EFADEC6-6E22-482A-9810-5B0822653235
10:40:48        An error was encountered processing the command (code=146):
10:40:48        Unable to erase contents and settings in current state: Creating
10:40:48      # ./image_library_tests/image_library_regression.rb:67:in `block (4 levels) in <top (required)>'
  • This means the virtual device, got corrupted and needs to removed and added back in, doing it command line often doesn’t work.
    1. Go to the VM in question, launch the iPhone simulator.  You will probably get a pop up (the “device” trying to display with a message notification that has the unable to erase message.
    2. Switch to a different device, by going to the menu for the Simulator and clicking on Hardware -> Devices and choosing any other device.
    3. Then go to Hardware -> Devices -> Manage Devices (button of the device list)
    4. When the pop up appears, select the problem device and choose delete (if you son’t switch devices first (step 2) this device will be active and you can’t delete it)
    5. Then hit the plus key “+” (at the bottom) and then create a new version of the device you just deleted (in my case I had to delete an iPhone 6 and create a new iPhone 6)
    6. You’re done, just update any files that might use the unique identifier in them

Running a specific spec (e.g. test)

This is mostly a note to myself – babysteps, I was in the spec directory and tried running:

  • rspec my_test.rb

Bad idea, it ignored the my_test.rb and tried running through all the specs (test) in that directory, need to be on directory up (at least) and then run:

  • rspec spec/my_test.rb

So that only the one test suite is run.

 

Adding an image(s) to the iPhone Simulator

I managed to finally get an image to into my iPhone Simulator, running into a problem now, I can’t find the image to delete it or change.

Anyway once you if you know the device that is running (if not you can find out the GUID here:  https://qatesttech.wordpress.com/2015/04/22/determining-which-device-is-running-in-the-iphone-simulator/)

These steps then worked for adding images:

How to bulk upload images on the iOS Simulator. (I’ve only confirmed it on 6.1.)

  1. Backup the device folder:
    1. ~/Library/Application Support/iPhone Simulator/6.1/Media
  2. Copy all your images into the folder:
    1. ~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE
  3. Move or delete the folder:
    1. ~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData
  4. Restart iOS Simulator
  5. Open the Photos app

The simulator will restore all the images from the 100APPLE folder! – yours will be there too 

Notes:
  1. My Devices aren’t in this location, they are under ~/Library/Developer….
  2. I didn’t do step 1, since launching the Simulator copies missing stuff back
Now I have the problem that even though my image doesn’t appear in the 100APPLE directory, it still shows up when the simulator runs, though if I run the simulator manually, that image isn’t there.
Update 1:
  • This isn’t a solution for me (but might be for some folks:
    • As of iOS 8, you can just drag all your photos onto the simulator window and they’ll save to camera roll automatically. You can do as many at a time as you want.
Update 2:
So I copy the photo to 100APPLE, like mentioned above.  Now the photo seems to be there forever.  Even if I remove everything, the default stuff shows up, but when the simulator is run (invoked using Appium) the photos I previously manually added, reappear inside the phone Simulator.  If I launch the phone Simulator manually the photos aren’t there, so there is an Appium factor that I am unware of/not sure how it works.  Found out the image copy issue, it is all on me, not knowing all the parts of the interconnected system I inherited – education is good🙂
 Update 3:
A bit clunky, but command line nuking the image files in a folder while the iPhone Simulator is running
find ~/Path to Devices/(GUID of Device)/data/Media/DCIM/100APPLE/ -iname “*.jpg” -delete
Example:
find ~/Library/Developer/CoreSimulator/Devices/6A0CB955-C22B-48A6-A7F5-809806EB57F2/data/Media/DCIM/100APPLE/ -iname “*.jpg” -delete

Determining which “device” is running in the iPhone Simulator

I ran into a problem (again an issue with inheriting someone else’s system and trying to figure out how all the parts work.).  The System uses xCode, and Appium, and Ruby, and RSPEC.  In theory, according to the documention there is a configuration file, which based on the GUID tells me which “device” is running in the simulator.  Per this configuration file, which only has one line of text:

  • {“Simulator ID”: “FEE861DF-59E1-43EA-B17A-A3C289293B0C”}

The Device that is running should have a GUID of FEE861DF-59E1-43EA-B17A-A3C289293B0C.  So if I track that device down in the Developer Directory (see: https://qatesttech.wordpress.com/2015/04/22/resetting-an-iphone-simulator-and-clearing-images/ ),  I will find a device.plist, which has the device description.

According to the device.plist, I should be running an iPhone 6 with iOS 8.2, and this also lets me track down the image directory so I can put in the images I want to process with our App.  However when I ran the test suite, using the “magical” command:  rspec spec/business_card_spec.rb (which is rspec <sub-directory> and name of the test suite that needs to be run), the simulator launched fine, but when it opened the Photo Albums it had different photos and the version at the top of the simulator said “8.3” – so something isn’t quite right.

Fortunately I add a second window open (from trying to add images while the iPhone Simulator was running) and I ran the command:

  • xcrun simctl list

This provided some awesome insight, I got back this list (a bit hard on the eyes):

== Device Types ==
iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5)
iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s)
iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus)
iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6)
iPad 2 (com.apple.CoreSimulator.SimDeviceType.iPad-2)
iPad Retina (com.apple.CoreSimulator.SimDeviceType.iPad-Retina)
iPad Air (com.apple.CoreSimulator.SimDeviceType.iPad-Air)
Resizable iPhone (com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone)
Resizable iPad (com.apple.CoreSimulator.SimDeviceType.Resizable-iPad)
== Runtimes ==
iOS 8.3 (8.3 – 12F69) (com.apple.CoreSimulator.SimRuntime.iOS-8-3)
== Devices ==
— iOS 8.3 —
iPhone 4s (CF459D0C-F679-437D-894B-72FD95436AF1) (Shutdown)
iPhone 5 (C66C2BC3-9A6D-493D-A9D8-915E40363B7C) (Shutdown)
iPhone 5s (80B3FD17-5D99-4DF9-A0C9-372CAC091828) (Shutdown)
iPhone 6 Plus (632E3762-6129-4939-BAFF-B6F1099BD3F4) (Shutdown)
iPhone 6 (6A0CB955-C22B-48A6-A7F5-809806EB57F2) (Booted)
iPad 2 (B0D6162A-B01D-4BE1-929E-18855C29B847) (Shutdown)
iPad Retina (B74C3D84-99B0-43AF-8D75-2D29A1A7764B) (Shutdown)
iPad Air (52F8083B-D47D-4341-8B6C-E8C74384ED91) (Shutdown)
Resizable iPhone (0ADA273B-B83E-4C9B-B8BD-350494F2C7A8) (Shutdown)
Resizable iPad (4FFB59A3-11CA-4C29-A049-C62495A2D934) (Shutdown)
— Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-0 —
iPhone 4s (AD216DA2-6EF2-4CC5-9222-71FF8BBB5746) (Shutdown) (unavailable, runtime profile not found)
iPhone 5 (06BF26ED-6892-4BAF-9D94-5D92171A7C1A) (Shutdown) (unavailable, runtime profile not found)
iPhone 5s (142B5205-8506-4EB6-A80A-FEA8A6F022AC) (Shutdown) (unavailable, runtime profile not found)
iPhone 6 Plus (015F9A02-CC77-4F9B-9E42-77FAF7AA6876) (Shutdown) (unavailable, runtime profile not found)
iPhone 6 (6299F3DE-44AE-4D86-84E8-E2A5C883BD4F) (Shutdown) (unavailable, runtime profile not found)
iPad 2 (DF9EEDF3-A0D0-48DA-AFC4-72C96999B9D4) (Shutdown) (unavailable, runtime profile not found)
iPad Retina (A7AAA454-46E3-4D73-AB3A-FE2F1C6E5B66) (Shutdown) (unavailable, runtime profile not found)
iPad Air (40D3CE5A-9059-4D3B-96AB-B736D21D20C6) (Shutdown) (unavailable, runtime profile not found)
Resizable iPhone (8164FE9D-AE3D-45D6-8429-5A06AA870262) (Shutdown) (unavailable, runtime profile not found)
Resizable iPad (8B586B7B-C618-4C8C-A10B-47B3CE0E37EA) (Shutdown) (unavailable, runtime profile not found)
— Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-2 —
iPhone 4s (2DA772B3-8ED2-4D2F-BB71-0CABFED9C3EC) (Shutdown) (unavailable, runtime profile not found)
iPhone 5 (C77D8C25-3D04-4E4B-B698-5E02B42B5857) (Shutdown) (unavailable, runtime profile not found)
iPhone 5s (7F057144-D6AC-4E58-BB59-60A677E97F6C) (Shutdown) (unavailable, runtime profile not found)
iPhone 6 Plus (EB5DB275-830C-4898-8F2F-FFBD23A5A3A9) (Shutdown) (unavailable, runtime profile not found)
iPhone 6 (FEE861DF-59E1-43EA-B17A-A3C289293B0C) (Shutdown) (unavailable, runtime profile not found)
iPad 2 (1F6BA798-DD20-42A3-B837-EBFFDE74C9BE) (Shutdown) (unavailable, runtime profile not found)
iPad Retina (D9B2B211-E32A-49ED-A474-D05DE16EFBE4) (Shutdown) (unavailable, runtime profile not found)
iPad Air (61256C66-4326-4646-86E6-161D6096869C) (Shutdown) (unavailable, runtime profile not found)
Resizable iPhone (09C6240A-BA0D-4875-9D6B-9D84A330D6B2) (Shutdown) (unavailable, runtime profile not found)
Resizable iPad (263A9CF2-6CBF-4A7D-9BD5-4B38323C1B5B) (Shutdown) (unavailable, runtime profile not found)

Tough to read, but I noticed the status “Booted” I was running a different iPhone 6 – GUID:  6A0CB955-C22B-48A6-A7F5-809806EB57F2, the device.plist there clearly shots it is configured for iOS 8.3.

Launched xCode and looked at the list of devices, and found the iPhone 6 with the GUID listed above, for some reason that is overriding the configuration file.  Next Task, tracking down why that is happening.

Apparently the information in appium.txt is overriding the configuration file.  In Appium.txt is list the device as “iPhone 6” which is a simulator device that can be found in

  • xCode -> Window -> Devices
    • This is how to get to “devices” in xCode 6.3.1

So I guess I need need to try fixing the images for GUID: 6A0CB955-C22B-48A6-A7F5-809806EB57F2

 

Resetting an iPhone Simulator and Clearing Images

In theory there is this command, though I haven’t tried it yet and it requires the iPhone Simulator to be running

  • xcrun simctl erase device_UUID

Another option, which also requires the iPhone Simulator to be running is:

  • Within the iPhone/iPad simulator, go to the top-menu and select “iOS Simulator” -> “Reset Content and Settings…

However what I really need is control over the images of the device.

One Stack Flow Article mentioned this location

  • /Users/<username>/Library/Application Support/iPhone Simulator/User/Applications
    • There are a bunch of GUID files and directories. They match up to the apps you have installed on your simulator.

I couldn’t find a folder called “iPhone Simulator”, this might be due to how my installation was setup (I followed someone else’s instructions during a knowledge dump). However I did finally find my Simulator files under “Developer”

Devices

  • /Library/Developer/CoreSimulator/Devices
    • Under Devices is a list of Directories that use the GUID as the folder name, you can find these GUID’s in the device list in the iPhone Simulator

Devices

Now that you found the directories you can remove the images if you wish, but going to a sub-directory under data (under your device)

  • /Library/Developer/CoreSimulator/Devices/GUID/data/Media/DCIM/100APPLE

Example:

  • /Library/Developer/CoreSimulator/Devices/06BF26ED-6892-4BAF-9D94-5D92171A7C1A/data/Media/DCIM/100APPLE
    • I’m not sure if the sub-directory is always called “100APPLE” but that is the image directory

 

100APPLE

 

So resetting the iPhone Simulator, puts all the default photos back (like roaches🙂 , they can’t be nuked by a reset).  So the search continues, and I do dislike postings the same “manually” drag photos or something, that kind of defeats the purpose of automation.

 

Adding an image to the iPhone Simulator via the command line

So from the notes I was given, this is the command to make it work

xcrun simctl addphoto 6A0CB955-C22B-48A6-A7F5-809806EB57F2 /Users/username/Dropbox\ \(Evernote\)/Scannable\ Image\ Library/Moleskine.jpg

Which failed for me.

An error was encountered processing the command (code=146):
Invalid device state

Then I found out that you need the iPhone Simulator running first to make this work, considering I got the notes and overview in a knowledge before someone left the company, I can understand how details like that were lost.

So you need the iPhone simulator running and the command will add an image to the iPhone Simulator (though this caused other failures for)

So Command Usage

  • xcrun (Run or locate development tools and properties Command line)
  • simctl (Command line utility to control the iOS Simulator)

So me in this case I need to add a photo for processing by our app, fortunately there is a command “addphoto”

  • xcrun simctl addphoto (Device ID) /PATH To Image
    • Note 1: Simulator needs to be running for this command to work
    • Note 2: You can drag an image to the command line and OSx will put in the path to the image for you
  • Example: xcrun simctl addphoto 6A0CB955-C22B-48A6-A7F5-809806EB57F2 /Users/username/Dropbox\ \(Evernote\)/Scannable\ Image\ Library/Moleskine.jpg
    • username = your actual username

 

 

Other Things.

I have been off Android testing for a while, moved to other devices and platforms in the office.  Now I am on iOS Testing for our apps and we aren’t doing any active development with Android.  I will post future Android test here when we return to Android testing.  So a few Apple related things will appear here, sorry if that offends the Android folks, but the day job is “breaking things” any platform🙂

adb devices reporting Nexus 7 offline

Occasionally run into a problem when switching devices (unplugging one device and plugging in a different one to collect logcat information), “adb devices” reports my Nexus 7 (running 4.2.2) as offline.  Bouncing the adb service (adb kill-server, adb start-sever) doesn’t fix it, either use unplugging the device and plugging it back in.  So far, one method (discovered by accident seems to work the best) – putting my mac to sleep (this often happens due to having to attend meetings) when I return and run “adb devices” again,the Nexus 7 is no longer offline – wacky but it least it works.  Will try putting the mac to sleep on purpose next time to see if it works.

Finding shell command options and memory usage

Filesystem disk space usage

  • adb shell df

 

For a list of all the available shell programs, use the following command:

  • adb shell ls /system/bin
Which returned:

  • adb shell ls /system/bin
    • abcc
    • adb
    • am
    • app_process
    • applypatch
    • atrace
    • bmgr
    • bootanimation
    • btmacreader
    • bu
    • bugmailer.sh
    • bugreport
    • cat
    • chmod
    • chown
    • cmp
    • content
    • cp
    • dalvikvm
    • date
    • dbus-daemon
    • dd
    • debuggerd
    • dexopt
    • df
    • dhcpcd
    • dmesg
    • dnsmasq
    • drmserver
    • du
    • dumpstate
    • dumpsys
    • fsck_msdos
    • getevent
    • getprop
    • glgps
    • grep
    • gzip
    • hd
    • hostapd
    • id
    • ifconfig
    • iftop
    • ime
    • input
    • insmod
    • installd
    • ioctl
    • ionice
    • ip
    • ip6tables
    • iptables
    • keystore
    • kill
    • linker
    • ln
    • log
    • logcat
    • logwrapper
    • ls
    • lsmod
    • lsof
    • make_ext4fs
    • md5
    • mdnsd
    • mediaserver
    • mkdir
    • mksh
    • monkey
    • mount
    • mtpd
    • mv
    • nandread
    • ndc
    • netcfg
    • netd
    • netstat
    • newfs_msdos
    • notify
    • ping
    • pm
    • pppd
    • printenv
    • ps
    • racoon
    • reboot
    • renice
    • requestsync
    • rm
    • rmdir
    • rmmod
    • route
    • run-as
    • schedtest
    • schedtop
    • screencap
    • screenshot
    • sdcard
    • send_bug
    • sendevent
    • sensors-config
    • sensorservice
    • service
    • servicemanager
    • setconsole
    • setprop
    • settings
    • setup_fs
    • sh
    • sleep
    • smd
    • start
    • stop
    • surfaceflinger
    • svc
    • sync
    • system_server
    • tc
    • tf_daemon
    • toolbox
    • top
    • touch
    • uiautomator
    • umount
    • uptime
    • vdc
    • vmstat
    • vold
    • watchprops
    • wipe
    • wpa_supplicant

 

“Re-imaging” a Device – or flashing a Rom

Had a problem where I was added  a phone that someone had tried to install ubuntu (Linux flavor) on it, it failed and they just put it back on the shelf int he lab😦

Took me a couple tries to figure out how to put a usable version of Android back on the device.

What I went through:

  1. Figure out what model phone I had – had to pop the case and read behind the battery – since didn’t tell me the carrier, fortunately IT had that info
  2. Then I needed to find the right Rom (image) for the device and download the zip file for it to my computer (first image failed)
  3. Then I copied the image to the SDCARD of the phone:
    • adb push bigxie_maguro_JRN84D_v2-signed.zip /sdcard/bigxie_maguro_JRN84D_v2-signed.zip
  4. Then on the phone I “Flash Zip from SD Card”
  5. And choose that zip above, it took  a few minutes to unpack the zip file and boot – but it worked.

Command line I also used the commands “adb reboot” and “adb reboot recovery” to keep booting my phone

For the Roms, I found the images here:  http://www.clockworkmod.com/rommanager

For Additional Flashing/imaging instructions:  Flashing Guide – http://forum.xda-developers.com/wiki/index.php?title=Flashing_Guide_-_Android