📜 ⬆️ ⬇️

How to facilitate the installation of .apk on Android or GUI for adb install

Good day, dear Habravchane! It so happened that I often have to install .apk-files on Android devices - I work as a tester. And once again, opening the terminal and dialing the command to install the next application, I thought about how to get rid of the routine work. The article is intended for beginners, so there will be a lot of explanations.
First, let's recall the command syntax: adb install < > . If 2 or more devices are connected, we get:
error: more than one device and emulator
- waiting for device -
Since adb does not know where to put the application. To explicitly specify the device, use the adb -s <ID_device> installl < > . To get the ID_device, you need to issue the adb devices command, which will list the connected devices:
List of devices attached
LGOTMS409c0d device
HT0BTHG02888 device
Using the script below, you can make the installation process more user friendly.
Listing script:
 #!/bin/bash DEV_LIST=$(adb devices | awk '/device$/{if (NR!=1) {print $1}}') #   ,   .apk  DIR_PATH="/home/dn010891laa//" while [ -z "$DEV_LIST" ]; do zenity --question --title="    Android-" --text=" ?" --height=100 --width=400 if [ $? -eq "0" ]; then DEV_LIST=$(adb devices | awk '/device$/{if (NR!=1) {print $1}}') else notify-send "ADB" " " exit fi done path=$(find "$DIR_PATH" -name "*.apk*" | zenity --list --title "    "$DIR_PATH"" --column "  .apk" --height=370 --width=600) if [ $? -eq "1" ]; then exit fi if [ $(echo "$DEV_LIST" | wc -l) -ne "1" ] then DEV_NAME=$(zenity --list --title "     ?" --column " " $(echo "$DEV_LIST" | xargs)) if [ $? -eq "1" ];then notify-send "ADB" " " exit fi else DEV_NAME="$DEV_LIST" fi adb -s "$DEV_NAME" install "$path" | tee /tmp/installlog.txt | zenity --progress --text " "$path"   "$DEV_NAME"" --pulsate --auto-close --no-cancel log=$(cat /tmp/installlog.txt) zenity --info --title=" " --text="$log" rm /tmp/installlog.txt killall adb exit 

Now in order:
one.
Zenity is used to interact with the user - a graphical interface for the command line. You can familiarize yourself with the command line parameters in the Internet, for example, here , or by running zenity --help in the terminal
DIR_PATH is the way where all apk are folded by default, this option is convenient for me personally. If the path to the file is not permanent - you need to erase the line with DIR_PATH, and for the path variable specify zenity --file-selection --title=" apk " --file-filter=*.apk - then the "Select file "with the choice of any path and filter by file extension *. Apk.
2
  DEV_LIST=$(adb devices | awk '/device$/{if (NR!=1) {print $1}}') 
- We get the output of the adb devices command, delete the extra text from the lines, in this case the text “device”, and output all the lines except the first one, since it contains unnecessary text “List of devices attached” - this is all assigned to the DEV_LIST variable.
3
  while [ -z "$DEV_LIST" ]</code>: <code>-z 
- returns true, if the length of the line is 0, I think that in the body of the loop, everything is clear.
four.
  path=$(find "$DIR_PATH" -name "*.apk*" | zenity --list --title "    "$DIR_PATH"" --column "  .apk" --height=370 --width=600) 
- we search for all files with the * .apk extension along the specified path, and output the result to the list via zenity - assign the selected path to the path variable
five.
  if [ $(echo "$DEV_LIST" | wc -l) -ne "1" ] 
- we read the list of devices, we get the number of lines, if there are more lines than 1, then we build the list:
  DEV_NAME=$(zenity --list --title "     ?" --column " " $(echo "$DEV_LIST" | xargs)) 
, the selected value is assigned to DEV_NAME.
6
  adb -s "$DEV_NAME" install "$path" | tee /tmp/installlog.txt | zenity --progress --text " "$path"   "$DEV_NAME"" --pulsate --auto-close --no-cancel 
- we give the installation command, in parallel we write the installation progress in the log file, and we transfer the parameters to zenity --progress - to display the progress zenity --progress . then after the installation is complete, we read the information from the log and display a message about the installation result. It looks like this:




After creating the script, make it executable, and run it.
I hope that the article will be useful. Thanks for attention.

')

Source: https://habr.com/ru/post/204160/


All Articles