Execute symbolicatecrash from shell script - ios

I am trying to call symboliccrash from a shell script that loops through multiple crash log file and outputs symbolicated version, but it is failing with an error message saying "command not found"
But it works fine in the command line.
symboliccrash CRASH_FILE.crash APP.dSYM > symbolicated.crash
I tried to find the source for symboliccrash but it fails to find it
which -a symboliccrash
Shell Script Code
#!/usr/bin/bash
export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"
i=0
for x in *.crash;
do
symboliccrash $x MyApp.dSYM > $i.crash
i=$((i+1))
done
Response
compareUUD.sh: line 7: symboliccrash: command not found
Any idea how i can do this.

I think that you need first of all is execute this command
find /Applications/Xcode.app -name symbolicatecrash -type f
on your Terminal, this will retrieve the localization of your symbolicatecrash something like this
/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash
then you need to update your script to this code
#!/usr/bin/bash
export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"
alias symbolicatecrash='/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash'
i=0
for x in *.crash;
do
symbolicatecrash $x MyApp.dSYM > $i.crash
i=$((i+1))
done
and replace the direction of symbolicatecrash for the result given by the execution of find /Applications/Xcode.app -name symbolicatecrash -type f
and that is it,execute with sudo sh, I tested and result in this error
No crash report version in 0.crash at
/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash
line 1007.
But I asume that this error is because I don't have any crash or dSYM so I think that now is working, I hope this help you

Related

cordova build error when `node cordova/lib/copy-www-build-step.js` in build phase

I am a web developer with no experience in iOS development. Now I'm using Cordova to build iOS app. Because I have no knowledge about iOS or Xcode, it is very hard for me. I always get error like the following output when I built in Xcode or built in command line.
Error info in Xcode build:
Run custome shell script 'Copy www directory'
PhaseScriptExecution Copy\ www\ directory /Users/jyjin/Library/Developer/Xcode/DerivedData/myios-auhioanpfinvvvcrnvoaioslreyr/Build/Intermediates.noindex/myios.build/Debug-iphonesimulator/myios.build/Script-304B58A110DAC018002A0835.sh (in target: myios)
cd /Users/jyjin/workspace/gitProject/Cordova/FirstProject/platforms/ios
/bin/sh -c /Users/jyjin/Library/Developer/Xcode/DerivedData/myios-auhioanpfinvvvcrnvoaioslreyr/Build/Intermediates.noindex/myios.build/Debug-iphonesimulator/myios.build/Script-304B58A110DAC018002A0835.sh
/Users/jyjin/Library/Developer/Xcode/DerivedData/myios-auhioanpfinvvvcrnvoaioslreyr/Build/Intermediates.noindex/myios.build/Debug-iphonesimulator/myios.build/Script-304B58A110DAC018002A0835.sh: line 2: 27158 Segmentation fault: 11 node cordova/lib/copy-www-build-step.js
Command PhaseScriptExecution failed with a nonzero exit code
Error info in command line build:
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Copy\ www\ directory /Users/jyjin/Library/Developer/Xcode/DerivedData/myios-auhioanpfinvvvcrnvoaioslreyr/Build/Intermediates.noindex/myios.build/Debug-iphonesimulator/myios.build/Script-304B58A110DAC018002A0835.sh
(1 failure)
xcodebuild: Command failed with exit code 65
I have read a lot of solutions on websites, and finally I found that there were some script in build phase:
NODEJS_PATH=/usr/local/bin; NVM_NODE_PATH=~/.nvm/versions/node/`nvm version 2>/dev/null`/bin; N_NODE_PATH=`find /usr/local/n/versions/node/* -maxdepth 0 -type d 2>/dev/null | tail -1`/bin; XCODE_NODE_PATH=`xcode-select --print-path`/usr/share/xcs/Node/bin; PATH=$NODEJS_PATH:$NVM_NODE_PATH:$N_NODE_PATH:$XCODE_NODE_PATH:$PATH && node cordova/lib/copy-www-build-step.js
after checking out the error message several times, I tried to remove && node cordova/lib/copy-www-build-step.js in Build Phases, it builds successfully, but with no page effect expected in html (Cause no www resource copied I think).
and I tried to check out some env PATH value in copy-www-build-step.js,so I wrote some log code in copy-www-build-step.js, but have no idea how to print js logs in Xcode. Then I found cordova-plugin-console, but npm doc said it is duplicated, and contains the last version for Cordova, and mine is also the latest.
Oh, God!One week passed... I just want to build an iOS app. It’s so hard to play. The ghost knows what I experienced:Configuring certificates, profile, building a Cordova app from scratch, even spending $99 to buy an apple developer account...
Just want to play an iOS app by myself in my free time ... Hope someone can help me ~~
-- From a desperate Chinese boy !
just update cordova-ios to latest version:
npm i cordova-ios#latest
you can see this problem being solved in this PR: #600, they changed the script from javascript to the old shell version and fixed the problem.
Workaround without updating the library
Enter in xCode in the Build Phases tab and click on "Copy www directory" phase, so change the script to:
$SRCROOT/__PROJECT_NAME__/Scripts/copy-www-build-step.sh
"__PROJECT_NAME__ " is the name of xCode project.
After this download the copy-www-build-step.sh script and put it inside the "__PROJECT_NAME__/Scripts/" path.
References
https://github.com/apache/cordova-ios/issues/540
https://github.com/apache/cordova-ios/pull/600/files
https://github.com/apache/cordova-ios/pull/146/files
Oh! I have fixed it~
Firstly, check the script:
NODEJS_PATH=/usr/local/bin; NVM_NODE_PATH=~/.nvm/versions/node/`nvm version 2>/dev/null`/bin; N_NODE_PATH=`find /usr/local/n/versions/node/* -maxdepth 0 -type d 2>/dev/null | tail -1`/bin; XCODE_NODE_PATH=`xcode-select --print-path`/usr/share/xcs/Node/bin; PATH=$NODEJS_PATH:$NVM_NODE_PATH:$N_NODE_PATH:$XCODE_NODE_PATH:$PATH && node cordova/lib/copy-www-build-step.js
currently error is xcodebuild: Command failed with exit code 65. This is the first error, the && should be & when running in the mac.
And then, the error turn to be Command /bin/sh failed with exit code 127.And I found xcode error message: node: command not found.
So I run find /usr/local/n/versions/node/* -maxdepth 0 -type d 2>/dev/null | tail -1 in the command line. and get the node result path /usr/local/n/versions/node/11.12.0
run
node -v // v10.15.3
So I remove all script in build_phases, and give it node path for my real nvm node path, change build_phases like below:
/Users/jyjin/.nvm/versions/node/v10.15.3/bin/node cordova/lib/copy-www-build-step.js
Build success!
Summary! cordova auto build_phases script maybe not suit your environment, make sure build phase can get your node path!

iOS: symbolicatecrash is stuck

symbolicatecrash is stuck.
I was trying to run it like this:
symbolicatecrash -v crash.txt MYAPP
The execution never ends. It used to work in the past but now (Xcode 7 and 8) it is stuck.
Is there a solution please?
Here is a solution:
The in-depth details appear here: iOS9: duplicated lines in crash reports are causing symbolicatecrash to get stuck
The quick solution is to edit this perl script (new location in Xcode 8!):
/Applications/Xcode.app//Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash
Now search for defined($images{$bundlename}) and add next; right after, like this:
if ( defined($images{$bundlename}) ) {
next;
That's all!
Some VERY USEFUL symbolication tips:
For symbolication you need 3 files:
A text file with the crash report: starting with Incident Identifier: and ending with something like 0x1974d0000 - 0x1974f3fff libxpc.dylib arm64 <ad580443238d39978d09004c210d0c18> /usr/lib/system/libxpc.dylib
The app folder, named MYAPP.app (the Finder hides the .app extension). If you have and IPA of the app, unzip it and it will be wishing the Payload folder.
The dSYM folder, as generated by Xcode while compiling.
You should rename the dSYM folder into MYAPP.app.dSYM and put all three files in the same folder.
All the three must have the same UUID. To verify that you can use the following commands (I got gsed by running brew install gnu-sed):
UUID of app: dwarfdump --uuid MYAPP.app/MYAPP
UUID of symbols: dwarfdump --uuid MYAPP.app.dSYM
UUID od crash:cat crash.txt | grep -A 1 "Binary Images:" | gsed -r -n -e 's_.*<([0-9a-z]{8})([0-9a-z]{4})([0-9a-z]{4})([0-9a-z]{4})([0-9a-z]{12}).*_\1-\2-\3-\4-\5_p' | awk '{print toupper($0)}'
Now, if they all match the same UUID, you can:
symbolicatecrash -v crash.txt MYAPP

Qt-creator examples fail to build for iphonesimulator

I've successfully installed Qt 5.7.0 and Qt-creator 4.1.0 on El Capitan with Xcode 8.
I fixed the xcode sdk-version errors from qt, and now I'm trying to build one of the examples for iphonesimulator. None of them work. All of them fail with error message of type:
The following build commands failed:
CopyPNGFile Debug-iphonesimulator/2dpainting.app/Default-568h#2x.png 2dpainting.xcodeproj/Default-568h#2x.png
I can confirm that directory Debug-iphonesimulator/2dpainting.app does not have the png-file, it's actually located somewhere within the qt installation directories. Copying the png to the source folder does not help as the folder gets overwritten upon running 'make'.
Any advice would be appreciated.
Edit:
The build kit warns about the following issue:
"Device type is not supported by the Qt version". Device type is 'iOS simulator'.
I had the same problem after I had updated my Xcode to version 8.0.
My first error was "Project ERROR: Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild."
To solve this problem, I created a symbolic link:
cd /Applications/Xcode.app/Contents/Developer/usr/bin/
sudo ln -s xcodebuild xcrun
Then I got error "Project ERROR: Current iphonesimulator SDK version (10.0) is too old. Please upgrade Xcode."
I commented two strings out in file QT_DIR/5.7/ios/mkspecs/macx-ios-clang/features/sdk.prf
lessThan(QMAKE_MAC_SDK_VERSION, "8.0"): \
error("Current $$QMAKE_MAC_SDK SDK version ($$QMAKE_MAC_SDK_VERSION) is too old. Please upgrade Xcode.")
Then I got error about emulator. Qt could not find it. I replaced line of code in file QT_DIR/5.7/ios/mkspecs/macx-ios-clang/xcodebuild.mk from:
IPHONESIMULATOR_GENERIC_DESTINATION := "id=$(shell xcrun simctl list devices | grep -E 'iPhone|iPad' | grep -v unavailable | perl -lne 'print $$1 if /((.*?))/' | tail -n 1)"
to:
IPHONESIMULATOR_GENERIC_DESTINATION := "id=$(shell xcrun simctl list devices | grep -E 'iPhone|iPad' | grep -v unavailable | awk 'match ($$0, /\(([A-F0-9\-]*\))/ ) { print substr ($$0, RSTART+1, RLENGTH-2) }' | tail -n 1)"
And finally afer all of it I got error "The following build commands failed:
CopyPNGFile Debug-iphonesimulator/Test01.app/Default-568h#2x.png Test01.xcodeproj/Default-568h#2x.png"
This error occurred due to the fact that the system has two file xcrun. And script /Applications/Xcode.app/Contents/Developer/usr/bin/copypng starts one, which is a symbolic link. Then I changed path in this script
from:
my $PNGCRUSH = `xcrun -f pngcrush`;
to:
my $PNGCRUSH = `/usr/bin/xcrun -f pngcrush`;
And then I finally had built the project without errors and opened it in Xcode.
I had this stupid error and spent two days to nail down. I was about to downgrade Xcode and thought lets try one more time. Finally nailed down.
Symptom:
The simplest project wont build from Qt Creator. The error I would get: CopyPNG failed or something along the line and a hint '-f' unknown parameter.
Reason: xcrun takes both -f and -find from the terminal I can see, but it does not like -f from the script copypng. (copypng is a perl script by the way.)
The solution: Open the file /Applications/Xcode.app/Contents/Developer/usr/bin/copypng and find
my $PNGCRUSH = `xcrun -f pngcrush`;
changed to
my $PNGCRUSH = `xcrun -find pngcrush`;
PS: I dint have path problem with xcrun, if you have it'd be good to put the whole path as advised above.

what does `{}` mean as a file name in output from egrep?

I am on ubuntu debian 12.04, and I ran a find command to add something to all of my python files:
find . iname "*.py" -exec echo "import os" >> {} \;
The command runs without error and I want to validate the results so I egrep all of the files:
egrep -in "import os" *
And I get results looking like this:
{}:35:import os
{}:36:import os
{}:37:import os
{}:38:import os
{}:39:import os
...and the numbers go until 51 for some reason. What does this mean?
Thank you.
Your first command:
find . iname "*.py" -exec echo "import os" >> {} \;
Is looking for files ending in .py, and for each one is putting the string "import os" in a file called {}. Presumably there are 51 matches.
So egrep, when you run it, the * matches all files, including your file called {}. With {}:35:import os it's telling you that "in the file {}, at line 35, there's the string you're looking for"
This command:
find . iname "*.py" -exec echo "import os" >> {} \;
...creates a file named {} (in bash, and other shells which honor redirections in positions other than head and tail -- this is an extension which the POSIX sh standard does not require). It does not modify the files found by find. (This is because the >> is acting as a command to the shell that's starting find; it's not modifying the behavior of -exec -- and even if it did, -exec directly uses execve() to invoke the command given; it doesn't start that command through a shell, so it doesn't honor shell constructs such as redirections, so you'd be passing literal >> as an argument to echo on any shells not implementing this extension, still not performing a redirection on the individual files found).
Now, if you did want to modify the files found by find, you might do so like this:
find . -iname '*.py' -exec sh -c 'for f; do echo "import os" >>"$f"; done' {} +
Noteworthy differences:
The redirection is invoked inside a shell started with exec sh; thus, there's a shell present to honor it after the individual filenames have been resolved.
-exec ... {} + is used, which is much more efficient than -exec ... {} ; (the former runs as few subcommands as possible; the latter runs one per file found).
{} is a placeholder that is replaced by find with the filename that matches the given condition, in this case {} is replaced with filename that match the pattern "*.py".
However your find command isn't actually doing that, as the >> {} is not actually part of the -exec block, but interpreted by the shell as a redirect for the whole find command, so the {} never gets replaced by find with the proper filename and instead you are redirecting into a file called {}. To make things more clear, the command you are actually executing is this:
find . iname "*.py" -exec echo "import os" \; >> {}
Meaning for every *.py file you add a line containing "import os" into a file called {}. The output of grep is just filename:linenumber:matched_line so you get a {} in there as that is the filename.
If you are wondering how the \; survives and why you are not getting a:
find: missing argument to `-exec'
The shell doesn't actually care where in the command line the redirect occurs:
echo 1 2 3 4 5 6 7 > foo
is the same as:
echo 1 2 > foo 3 4 5 6 7
and gives you this each time:
$ cat foo
1 2 3 4 5 6 7
Also worth to mention >> is an append operator, so even if you fix your command you are adding to the end of the Python files, while import os probably should go to the top of the file.

How to symbolicate crash logs using the .xcarchive file?

I am having issues extracting the dsym file from .xcarchive to symbolicate crash logs. I understand that .xcarchive contains both the .app files and .dsym files. Normally you should be able to right click on the xcarchive file and selecct "Show Package Contents" (link). However "Show Package Contents" does not show up for me.
I also attempted to symbolicate the crash logs manually by using symbolicatecrash and giving it the xcarchive file (link). However it would still return crash logs that were not symbolicated.
Would anyone know what could be going on here? Any help is appreciated, Thank you!
I have prepared a script which takes two parameters,
MyApp.crash
MyApp.xcarchive
And gracefully output the MyApp_symbolicated.crash
Scripts:
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Argument missing [symbolicate #logLocation #xcarchiveLocation]"
exit 0
fi
if test -e "$1"; then
echo "$1 exists"
else
echo "$1 does not exist!"
exit 1
fi
if test -e "$2"; then
echo "$2 exists"
else
echo "$2 does not exist!"
exit 1
fi
parentdir=`pwd`
export DEVELOPER_DIR=`xcode-select -p`
PATH=$PATH:$DEVELOPER_DIR
echo $PATH
cd $DEVELOPER_DIR
cd ../SharedFrameworks/
commanddir=`pwd`
command=$commanddir/`find . -name symbolicatecrash`
cd $parentdir
crashlog="$1"
archive="$2"
outputdir=`dirname "$crashlog"`
nfile=$(echo $1 | rev | cut -f 2- -d '.' | rev)
outputfile="$nfile"_symbolicated.crash
echo $nfile
desymfile="$archive"/dSYMs/*.dSYM
$command -v "$crashlog" "$desymfile" > "$outputfile"
How to use:
create a file symbolicate in /usr/local/bin/
Put the above code in symbolicate file
set execute permission with chmod 777 symbolicate
Run from wherever in your location with proper params
output will be generated in same directory of crash file.
Plug an iOS Device into the Machine that contains the archive in the designated archives folder.
Open the devices window in Xcode.
Open device logs.
Drag an drop your crash report into the list of logs of the device. Wait until it gets resymbolicated.

Resources