Find Xcode installation path by version - xcode

There are no standard paths to keep different copies of XCode (XCode3 and XCode4) on one system. For my Makefile or other commandline based build process, I am searching for a way to determine to installation path ($DEVELOPER_DIR) of XCode of a specific version, to export this path as DEVELOPER_DIR or use xcode-select to make it active.
So far I am trying to query system_profiler's xml output.
Are there any other (more convenient) options?
Basically I need a script to tell the system to use Xcode3 (or Xcode4) without knowing their installation paths.

Here's what I have come up with so far:
DEVELOPER_DIR=`system_profiler SPDeveloperToolsDataType -xml |\
xpath "//*[text()='spdevtools_version']/following-sibling::string[starts-with(text(),'3')]/../*[text()='spdevtools_path']/following-sibling::string[1]/text()"`
This sets DEVELOPER_DIR to the installation path of Xcode3. For Xcode4 just replace the '3' by '4'
This will not work as expected when multiple versions of XCode3 are installed.

You can find out the installation paths of all installed Xcode versions from the command line by querying the Launch Services database with the lsregister command.
To find all Xcode3 installation paths, run:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep --before-context=2 "com.apple.Xcode" | grep --only-matching "/.*\.app"
To find all Xcode4 installation paths, run:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep --before-context=2 "com.apple.dt.Xcode" | grep --only-matching "/.*\.app"
Also see this question.

This will find Xcode with given version in Applications folder assuming its name starts with Xcode:
for xcode in ls /Applications/Xcode*; do
if grep -q -s -E "<string>$1\.[0-9.]+</string>" "$xcode/Contents/version.plist"; then
echo "$xcode/Contents/Developer\c"
break
fi
done
Save this as findxcode.sh and then launch like this: ./findxcode.sh 9 and it will print you the path of Xcode 9 which you can put into DEVELOPER_DIR. The \c at the end is there to remove new line at the end if you need to capture the output with other script/fastlane or something.

Related

How to get the installer path/name from the MAC UI installer(.pkg) start page

We are trying to fetch installer path/name from the MAC UI installer before displaying the Custom nib file.
Below are the options tried:
hdiutil info -plist
Getting the environment variable $PACKAGE_PATH
Scanning the current directory
ps -eaf for listing the installer process name.
I needed to perform the same task today and the best approach I've discovered is to tail or cat the /var/log/install.log file just after the pkg is launched & grep for ".pkg".
tail /var/log/install.log | grep ".pkg"
This prints the path & name of the most recently launched pkg file. From there, I can parse the line of the last occurrence to extract my own installer's path & name:
2022-04-21 12:50:01-04 mbp Installer[29570]: Opened from: /Users/[myuser]/Downloads/[myPkgFile].pkg
2022-04-21 12:50:01-04 mbp Installer[29570]: Product archive /Users/[myuser]/Downloads/[myPkgFile].pkg trustLevel=350
Note: So far, I've only tested this on Big Sur 11.6. The log syntax may differ on older or newer versions. I expect, though, that it hasn't changed much over the years.

How could I get the full path of a file with file name?

[ SOLUTION ]
Thanks to #oguzismail and #stylo I find the solution. In the find command I modified the 2>&1 for 2>/dev/null and deleted the grep command, but I found the problem that it retrieves me two different path (because Android studio it was generation two different apk with the same name in two different paths).
To only get the path of the apk I want, I add a "filter" for my find command so the solution is:
find / -path ./intermediates -prune -o -name app-ipd-debug.apk 2>/dev/null
with name of the folder ./intermediates and -prune -o I can get the path I wanted to.
I saw the solution in this post
[ PROBLEM ]
I am doing a shell script that build an android project, install apk and do some more configurations in the device like set owner device owner (is a kiosk mode app) and some more stuff.
Now I am trying to dynamically build the project and get the apk file to install in the device but it doesn't work correctly.
I try putting the full path as a variable in my shell script and this works installing the app using the command adb install:
adb install -t -r $APK_PATH
I have tried t get the APK_PATH with find command but it retrieves me a lot of output that I don't know how to handle it, the command is :
find / -name apk-file-name.apk
A lot of output with "Permission denied" and "Operation not permitted" is shown and in one line of those the apk path is shown (this is the one I don't know how to get it, only this result)
I try to filter the results using grep but it doesn't work
find / -name apk-file-name.apk 2>&1 | grep -v "Operation not permitted"
and
find / -name apk-file-name.apk 2>&1 | grep -v "Operation not permitted"|"Permission denied"
any help?
You can use the locate command to locate files in your file system.
if you haven't enabled it yet, you can do so by running the following command
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
you won't be able to use it for a few minutes since it will index everything and later on you can use locate file_name.apk to find the file you're looking for.

can't run zipalign.exe in mac [duplicate]

When I try to run Zipalign on an apk I get the error "Command not found"
I am not that familiar with using terminal commands on the MAC but I have navigated to the SDK/Tools folder and run the following command:
zipalign -v 4 Project1.apk Project1-aligned.apk
I get Command not found
I have tried placing the apks in the Tools folder and same result.
Can someone help me to understand where the apks should be located and where I should run zipalign from?
Thanks, I am very frustrated about this as it seems so simple.
You can find correct path with this command:
find ~/Library/Android/sdk/build-tools -name "zipalign"
Perhaps the current directory is not in your path?
Try adding "./" before your command so
./zipalign -v 4 Project1.apk Project1-aligned.apk
You will find the zipalign tool at /path/to/sdk/build-tools/<build-tools-version>/zipalign NOT in the tools folder anymore.
~/Library/Android/sdk/build-tools/xxxx/zipalign
Drag this to terminal or save this in your path.
xxxx -> Version
Zipalign is a command that located at $ANDROID_HOME/build-tools/{android-version}/.
Hope it helped.
A simple one-liner:
This adds a line in your profile, to add the directory which contains the zipalign executable to your path
Then reloads the profile
echo "export PATH=\$PATH:~/Library/Android/sdk/build-tools/23.0.1/" >> ~/.bash_profile && . ~/.bash_profile
Make sure to replace 23.0.1 with your installed version
$ ls -l ~/Library/Android/sdk/build-tools/
total 0
drwxr-xr-x 23.0.1 <---
Now you should be able to use zipalign regardless of your current working dir
$ zipalign
on the mac with the zsh console, my solution was
command 1)
find ~/Library/Android/sdk/build-tools -name "zipalign"
----------------------------------------------------------
/Users/macOs/Library/Android/sdk/build-tools/28.0.3/zipalign
/Users/macOs/Library/Android/sdk/build-tools/26.0.2/zipalign
/Users/macOs/Library/Android/sdk/build-tools/25.0.2/zipalign
/Users/macOs/Library/Android/sdk/build-tools/27.0.3/zipalign
command 2)
echo "export PATH=\$PATH:~/Library/Android/sdk/build-tools/28.0.3/" >> ~/.bash_profile && . ~/.bash_profile
command 3)
ls -l ~/Library/Android/sdk/build-tools/
command 4)
zipalign -v 4 app-release-unsigned.apk nameApp.apk
2hours resume for newbies (like me) :
If you type this command :
zipalign -v 4 platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk app-release.apk
Witch gives you :
command not found: zipalign
It's maybe that the path is somewhere wrong.
If you have this :
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/bin/apt" (-1)
It confirms that its not really as it should be. So, to execute zipalign and finally publish your app, you have to go in the correct repository and execute commande.
1. Go to the correct repo to execute command :
The path is cd /Users/xxxyour_user_namexxx/Library/Android/sdk/build-tools/xxxxx/
cd /Users/greg/Library/Android/sdk/build-tools/28.0.3
2. Execute your zipalign command, don't forget to precise the path of apk file :
Obviously, chance "greg" and "myapp" with your user name & app name.
./zipalign -v 4 /Users/greg/Desktop/AppLocal/myapp/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk /Users/greg/Desktop/AppLocal/myapp/platforms/android/app/build/outputs/apk/release/app-release.apk
Hope it helps.
Search it and reference it... I have it here and reference it like this:
/Users/lioncio/Desktop/adt-bundle-mac-x86_64-20140702/sdk/build-tools/android-4.4W/zipalign bla bla bla (all the options of the command!)
And worked
Relax! , Just Use Locate Command in Terminal WHEREVER it is , it will come out
tom-MacBook-Air:kavform_app tom$ locate zipalign
/Users/tom/Software/android-sdk-macosx/build-tools/24.0.1/zipalign
/Users/tom/Software/android-sdk-macosx/docs/tools/help/zipalign.html
In my case it was burried over here
/Users/tom/Software/android-sdk-macosx/build-tools/24.0.1/zipalign -v 4 /Users/tom/kavwork/kavform/kavform_app/platforms/android/build/outputs/apk/android-release-unsigned.apk BrideToBe.apk
add it to the path
on terminal
find path for zip align
find ~/Library/Android/sdk/build-tools -name "zipalign"
path: /Users/username/Library/Android/sdk/build-tools/26.0.1/zipalign
enter the path found in there
sudo nano /etc/paths
now on new terminal you can see zipalign reco
Solution for Mac
This error basically means that the terminal wasn't able to find the zipalign file.
So you can either type in the full path for your zipalign file with the command (located in your Android build-tools folder)
/Users/username/Library/Android/sdk/build-tools/26.0.1/zipalign -v 4 android-armv7-release-unsigned.apk helloWorld.apk;
If you do not know the location of the zipalign file, then just use this command
find ~/Library/Android/sdk/build-tools -name "zipalign"
If you are working on Windows, change the command prompt to point to the folder containing the zipalign.exe and then run the command. Also, I have found that you are not using the complete command:
zipalign [-f] [-v] 4 Input.apk Output.apk
cd android-sdk/build-tools/22.0.0/ - change directory to android sdk folder, build tools and choose version (I used 22.0.0).
Then at the prompt type:
./zipalign -v 4 /MyApp/android-x86-release-signed.apk ~/MyApp/android-x86-release-signedandzipped.apk
That worked for me. I tried the other solutions above with no success. I just had to run the command withn the proper folder, but that wasn't explained clearly in other resources I checked.
Navigate to the path of the zip align and include that with the command
/Users/ignatiusandrew/Library/Android/sdk/build-tools/25.0.2/zipalign 4 android-release-unsigned.apk igi.apk
Alternatively, if you do not want to add a specific build tools folder to the path, in case it changes in the future, you can use the first result of find command:
$(find ~/Library/Android/sdk/build-tools -name "zipalign" | head -n 1) <your-zipalign-parameters>
It might be especially useful in a CI pipeline.
for me this worked perfectly, I copied the zipalign file from the android path to the folder where I wanted to run command and then typed ./zipalign -v 4 android-release-unsigned.sdk nameofapp.apk
Note: It was on Mac
%ANDROID_HOME%\\build-tools\\25.0.2\\zipalign -v 4 .\\platforms\\android\\build\\outputs\\apk\\input.apk .\\path\\ output.apk
First,
if your android home is set, then you can just
cd $ANDROID_HOME
and
open . (This should be - /Users/username/Library/Android/, you can just cd to that path as well)
Next, navigate to "sdk/build-tools/25.0.3/" (version 25.0.3 in this case, yours may be a different version).
At your terminal (apk prompt), drag zipalign to the terminal and
...../zipalign -v -p 4 my-app-unsigned.apk my-app-unsigned-aligned.apk.
Should work fine.
Hope it helps.
Downloaded zipalign-file from github
zipalign exec copy and paste in your Project1-aligned.apk directory
./zipalign -v 4 Project1.apk Project1-aligned.apk
In my case
I follow below answer
Change directory
/path/to/sdk/build-tools//zipalign
Type
./zipalign instead zipalign
In short ./zipalign is solution for me.
Solution for Jenkins
For Jenkins users using MacOS to build and sign mobile apps who are experiencing this error, the solution could be this:
At the stage where the signature is made:
withEnv(['PATH=/Users/jenkins/Library/Android/sdk/build-tools/29.0.3',
'ANDROID_SDK_ROOT=/Users/jenkins/Library/Android/sdk',
'JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home'])
I am using Windows with git bash/command promt
zipalign.exe needed to be configured in environment variables.
so include sdk folder 'build-tool' with android version folder you are using to build.
e.g. E:\android-sdk\build-tools\22.0.1
it should contain 'zipalign.exe'. now you can user
zipalign -v 4 Project1.apk Project1-aligned.apk
from any location using command line tools.
thumb up for me so i can help more developers.

How to uninstall Xcode 5 command line tools (Mac OS X 10.9 Mavericks)? [duplicate]

I upgraded to xcode 5 Command Line Tools on Friday. Something is not working correctly and I want to go back to the last 4.x version ox xcode. How do I uninstall xcode 5 command line tools? I don't see anything in the release notes.
Depending on whether you are running Xcode 5 in Mavericks or not, you will need to do two different things to uninstall the command line tools.
In Mavericks, Xcode includes its own copy of the Command line tools (i.e. they are bundled as part of Xcode.app). Therefore, uninstalling the Xcode (check instructions below) will remove the Command line tools too.
For older Mac OSX versions running Xcode 5 or older versions (Xcode 4.x), you can find previous SO answers which explain how to uninstall Xcode's command line tool. You can use this script (Read more about it in this post):
# remove_CLI_tools.sh
# written by cocoanetics:http://www.cocoanetics.com/2012/07/you-dont-need-the-xcode-command-line-tools/
# modified by yoneken
#!/bin/sh
RECEIPT_FILE1=/var/db/receipts/com.apple.pkg.DevSDK.bom
RECEIPT_PLIST1=/var/db/receipts/com.apple.pkg.DevSDK.plist
RECEIPT_FILE2=/var/db/receipts/com.apple.pkg.clang.bom
RECEIPT_PLIST2=/var/db/receipts/com.apple.pkg.clang.plist
RECEIPT_FILE3=/var/db/receipts/com.apple.pkg.llvm-gcc4.2.bom
RECEIPT_PLIST3=/var/db/receipts/com.apple.pkg.llvm-gcc4.2.plist
RECEIPT_FILE4=/var/db/receipts/com.apple.pkg.DeveloperToolsCLI.bom
RECEIPT_PLIST4=/var/db/receipts/com.apple.pkg.DeveloperToolsCLI.plist
if [ ! -f "$RECEIPT_FILE4" ]
then
echo "Command Line Tools not installed."
exit 1
fi
echo "Command Line Tools installed, removing ..."
# Need to be at root
cd /
# Remove files and dirs mentioned in the "Bill of Materials" (BOM)
lsbom -fls $RECEIPT_FILE1 $RECEIPT_FILE2 $RECEIPT_FILE3 $RECEIPT_FILE4 | sudo xargs -I{} rm -r "{}"
# remove the receipt
sudo rm $RECEIPT_FILE1 $RECEIPT_FILE2 $RECEIPT_FILE3 $RECEIPT_FILE4
# remove the plist
sudo rm $RECEIPT_PLIST1 $RECEIPT_PLIST2 $RECEIPT_PLIST3 $RECEIPT_PLIST4
echo "Done! Please restart XCode to have Command Line Tools appear as uninstalled."
You can run this easily by opening a Terminal and running this command (it will download the script and execute it automatically):
curl "https://gist.github.com/yoneken/3284561/raw/db665bb64f93e38ce138b5ca620b9edd18dc31e4/remove_CLI_tools.sh" | sh
If everything worked fine, you could open Xcode and see that the Command Line Tools appear as to be installed.
Then, depending on what you want, you could downgrade Xcode to a lower version and reinstall the Command Line Tools for that version, for example.
To downgrade Xcode, as explained in this SO answer:
Uninstall Xcode 5: go to /Applications and delete the Xcode app.
Restart the Mac.
Then you can download the desired Xcode version from here and install it from scratch.
I stumbled upon this while trying to uninstall Command Line Tools v6.
I had the full Xcode 6 installed, but moving Xcode to trash did NOT uninstall/delete CLT as well. I still had /usr/bin/clang for example. The solution was to manually remove CLT using the .bom contents (similar to #veducm's answer):
cd /
lsbom -fls /var/db/receipts/com.apple.pkg.CLTools_Executables.bom | sudo xargs -I{} rm -rf "{}"
lsbom -fls /var/db/receipts/com.apple.pkg.DevSDK_OSX109.bom | sudo xargs -I{} rm -rf "{}"
sudo rm /var/db/receipts/com.apple.pkg.{CLTools_Executables,DevSDK_OSX109}.{bom,plist}
Replace DevSDK_OSX109 with the version you have. You may have multiple ones, in which case, apply the same command to all of them (e.g. I had both DevSDK_OSX109 and DevSDK_OSX1010 because I had installed CLT for Mavericks and Yosemite too).
NOTE: This will delete the files listed in the .bom. You can view the contents them first by doing just lsbom -fls /var/db/receipts/com.apple.pkg.CLTools_Executables.bom etc if you are unsure.
NOTE2: You need the cd / since paths reported by lsbom are relative. You can also remove CLT by simply doing rm -rf /Library/Developer/CommandLineTools.
The rm command removes (deletes) files or directories.
Delete CLT from following command
sudo rm -rf /Library/Developer/CommandLineTools
from terminal.

Why can't mysqldumpslow.pl find any Perl modules on Windows?

I'm trying to parse a MYSQL slow query log from the command line.
Upon entering this:
set PATH=G:\xampp\perl\bin\;%PATH%
cd /d G:\xampp\mysql\scripts
perl mysqldumpslow.pl -s c -t 10
The shell returns an error can't locate strict.pm in #INC (#INC contains: .) at mysqldumpslow.pl at line 8. BEGIN failed
In the perl directory in xampp, there is only one file perl.exe.
Am I missing perl modules/libraries? What do I need to read this log file?
A workaround is to find the location of strict.pm in your perl installation and to add the directory to the PERL5LIB environment variable, or to invoke perl with the
-I/path/to/strict.pm/directory option (see perlfaq8: How do I add a directory to my include path (#INC) at runtime?).
If you find more unsatisfied dependencies, keep adding directories to PERL5LIB or with additional -I options until your program can run.
(Though eventually you will probably get tired of this and fix/reinstall perl.)
UPDATE: Looking through the 1.7.3 XAMPP distribution, all of the perl library files are located under xampp\perl\lib and xampp\perl\site\lib, so
perl -IG:/xampp/perl/lib -IG:/xampp/perl/site/lib mysqldumpslow.pl -s c -t 10
is probably all that you need to do. YMMV if you have an older XAMPP distribution.
Your Perl installation seems to have been messed up in one way or another. I am not familiar with xampp, but I have a hard time believing they bundled just the perl.exe without the rest of the distribution.
Under G:\xampp\perl, there should be subdirectories such as lib, site etc.
strict is a core pragma and its absence indicates that you do not have a proper Perl installation.
In fact, I just downloaded xampp and it does contain lib and site\lib under xampp\perl (it is missing the documentation, but that is not essential to running Perl scripts).

Resources