I am trying to unzip files in my android (11) phone with ADB from the terminal (Ubuntu 20.04). I need to run a script from my Ubuntu laptop to unzip files on my phone.
I have already tried Busybox from this suggestion. With this app, I can unzip files after accessing the shell. I mean -
$ adb shell
a60q:/ $ cd /sdcard/
a60q:/sdcard $ unzip data.zip
Archive: data.zip
inflating: Screenshot from 2020-11-30 16-45-46 (7th copy).png
inflating: Screenshot from 2020-11-30 16-45-46 (10th copy).png
But when I try to use the direct command, it shows an error.
$ adb shell unzip /sdcard/data.zip
unzip: couldn't create file Screenshot from 2020-11-30 16-45-46 (7th copy).png: Read-only file system
Archive: /sdcard/data.zip
Rooting phone isn't an option. My questions are -
What can I do here to unzip from the terminal?
Is there any tool to make compressed zip files (in Android) from the terminal?
In order to successfully invoke the unzip command from the terminal you should explicitly specify the folder where the zip's content will be extracted, for instance:
adb shell unzip /sdcard/data.zip -d /sdcard
By invoking unzip --help you will get more information on the other parameters available as well.
Related
I am new to android sorry if i sound like a nub but .
I want to copy a tar file inside the device through adb . After that i would like to extract it inside the device through tar command line tool. Is it possible ? If yes how do i install tar ?
zsh: command not found: tar
Use
adb push 'pathOnDesktop' 'pathOnDevice'
For copying files already on the device to a different location use
adb shell cp source destination
tar utility is bundled with adb
Do to see available commands and arguments with tar
adb shell tar --help
and then
tar –xvzf filename
to extract the zipped files.
I'm trying to download Whatsapp on my laptop. I am using Ubuntu desktop software. I've installed Android Emulator from http://dl.google.com/android/android-sdk_r16-linux.tgz
I unzipped the file, opened the folder, Android-sdk-linux, opened Tools and now I'm supposed to execute the file Android, and I'm not sure how to do that. Can anyone give me any help?
Ok, so this is what I thought I was supposed to do:
shell#shell:~$ cd Desktop
shell#shell:~/Desktop$ ./android.sh
bash: ./android.sh: No such file or directory
but then that happens...
Make the file executable first with
chmod +x filename.sh
Then start the script with
./filename.sh
or
/full/path/to/filename.sh
sh filename.sh
OR
bash filename.sh
Use the following command to install the WhatsApp on Ubuntu:
wget https://www.thefanclub.co.za/sites/all/modules/pubdlcnt/pubdlcnt.php?file=https://www.thefanclub.co.za/sites/default/files/public/downloads/whatsapp-webapp_1.0_all.deb&nid=200 && sudo dpkg -i whatsapp-webapp_1.0_all.deb
Then enter the password and open WhatsApp using the application key.
by default permission for any shell script is "-rw-rw-r--" first we need to change the permissions using the "chmod command" then we can run the shell script in the same way in which we run the C executable code.
To debug the shell script we need to run the shell script with the "bash -x" option as follow : $ bash -x ./
I made a script to clean a ROM and install specific apps but when I look in the folder Mac is not seeing my .apk as unix exec file how can i fix this
here is part of the script:
getapex='curl -s -o ApexLauncher.apk apex.anddoes.com/Download.aspx'
$getapex
mv ApexLauncher.apk $currentdir/system/app/
hope you guys can help....
If it's not seeing the .apk file as a "unix exec file" as you say, then maybe you need to give it execution permission with:
chmod +x ApexLauncher.apk
I created several folders in the sdcard (Eclipse) by running an Android application in the emulator. Now I want to delete the folders which I have created on the sdcard.
I am able to delete files in the folders but I could not delete the folders in the sdcard.
How can I do this? Is there a way to delete folders?
Using adb command you can delete folders.
click Run - > CMD-> type adb shell --> cd sdcard -> rmdir {dirname}
Note : Make sure your dir should be empty.
For non-empty directory use.
click Run - > CMD-> type adb shell --> cd sdcard -> rm -r {dirname}
Well, answer from Brijesh Thakur is really helpful.
I just tried this and it worked fine for me to some extent. I would like to mention that if your directory contains any files then the rmdir command will not work. You will have to use rm -r command for that.
To make it more easy for beginners I am explaining the process as follows.
First you need to locate your adb folder, mine was at D:\Android SDK\platform-tools>
Now execute adb shell in a command prompt as:
D:\Android SDK\platform-tools>adb shell
A hash (#) symbol or dollar sign ($) will appear, then enter the following command:
# cd sdcard
Now you are in the sdcard of the device. If your folder is a sub folder then further locate its parent folder using the cd command. Finally, use the rm -r command to remove the folder recursively as follows. This will delete all files and directories in the folder.
# rm -r FolderName
Please note that if you want to remove a single file you can use the rm command only and then the file name (with extension probably). And you can also use rmdir command if the directory you trying to delete is empty.
Using adb shell with rm command you can delete(nonempty as well as empty) folders.
click Run -- > CMD--> type adb shell --> cd sdcard --> rm -r {dirname}
We can do it in a single command line as under:
adb shell rm -r sdcard/<dirname>
If you want to delete everything in your android file system, you need to get its storage name from adb!
# adb shell echo $EXTERNAL_STORAGE
It will give you the path where everything is stored!It will print the storage name in command line, for few devices it is /sdcard and for few, it is /storage/emulated/legacy etc
Now you want to delete everything in that, you need
# adb shell rm -r /sdcard/
that /sdcard/ is not same for all devices, it could be /storage/emulated/legacy/ for some devices!
warning-: It will delete every folder in your file manager except "android" folder
now if you want to delete a particular folder in that file manager
# adb shell rm -r /sdcard/FolderName
remount the sdcard with read and write permission:
adb shell mount -o remount,rw /
Go to adb shell:
adb shell
Delete file you want:
rm -r /sdcard/file_name
It will work most better.
I want to install a file using the Windows command line. First I want to build after compiling all the .jar files to create an .apk file for an Android application without using Eclipse.
Does anyone know how this can be done without the use of Eclipse & only by making use of command line.
You can use the code below to install application from command line
adb install example.apk
this apk is installed in the internal memory of current opened emulator.
adb install -s example.apk
this apk is installed in the sd-card of current opened emulator.
You can also install an apk to specific device in connected device list to the adb.
adb -s emulator-5554 install myapp.apk
Refer also to adb help for other options.
You can build on the command line with ant. See this guide.
Then, you can install it by using adb on the command line.
adb install -r MyApp.apk
The -r flag is to replace the existing application.
Use the Android Debug Bridge command line tool adb eg: adb install filename.apk.
A good reference for adb is Here
install [options] <PATH> Installs a package (specified by <PATH>) to the system.
Options:
-l: Install the package with forward lock.
-r: Reinstall an exisiting app, keeping its data.
-t: Allow test APKs to be installed.
-i <INSTALLER_PACKAGE_NAME>: Specify the installer package name.
-s: Install package on the shared mass storage (such as sdcard).
-f: Install package on the internal system memory.
-d: Allow version code downgrade.
uninstall [options] <PACKAGE> Removes a package from the system.
Options:
-k: Keep the data and cache directories around after package removal.
You can install an apk to a specific device/emulator by entering the device/emulator identifier before the keyword 'install' and then the path to the apk. Note that the -s switch, if any, after the 'install' keyword signifies installing to the sd card. Example:
adb -s emulator-5554 install myapp.apk
The simple way to do that is by command
adb install example.apk
and if you want to target connect device you can add parameter " -d "
adb install -d example.apk
if you have more than one device/emulator connected you will get this error
adb: error: connect failed: more than one device/emulator
- waiting for device - error: more than one device/emulator
to avoid that you can list all devices by below command
adb devices
you will get results like below
C:\Windows\System32>adb devices
List of devices attached
a3b09hh3e device
emulator-5334 device
chose one of these devices and add parameter to adb command as " -s a3b09hh3e " as below
adb -s a3b09a6e install example.apk
also as a hint if the path of the apk long and have a spaces, just add it between double quotes like
adb -s a3b09a6e install "c:\my apk location\here 123\example.apk"
Commands for install APK files like it does in Android Studio you can see below.
1) To push your app:
adb push /pathOfApk/com.my.awesome.apk /data/local/tmp/com.my.awesome
where com.my.awesome is your package.
2) To install:
adb shell pm install -t -r "/data/local/tmp/com.my.awesome"
Open Terminal in Android Studio
You might see
C:\Users\nikhil\AppData\Local\Android\Sdk\platform-tools>
copy and paste your apk which you want to install on above path inside platform-tools.
In my case app-qa-debug.apk I kept inside platform-tools folder.
install command
adb install app-qa-debug.apk
so in the terminal you could see something
C:\Users\nikhil\AppData\Local\Android\Sdk\platform-tools>adb install app-qa-debug.apk
post-installation you could get the message as
Performing Streamed
Install Success
Press Win+R > cmd
Navigate to platform-tools\ in the android-sdk windows folder
Type adb
now follow the steps writte by Mohit Kanada (ensure that you mention the entire path of the .apk file for eg. d:\android-apps\test.apk)
It is so easy!
for example my apk file location is: d:\myapp.apk
run cmd
navigate to "platform-tools" folder(in the sdk folder)
start your emulator device(let's say its name is 5556:MyDevice)
type this code in the cmd:
adb -s emulator-5556 install d:\myapp.apk
Wait for a while and it's DONE!!
You're likely here because you want to build it too!
Build
gradlew
(On Windows gradlew.bat)
Then Install
adb install -r exampleApp.apk
(The -r makes it replace the existing copy, add an -s if installing on an emulator)
Bonus
I set up an alias in my ~/.bash_profile
alias bi="gradlew && adb install -r exampleApp.apk"
(Short for Build and Install)
To install a debug (test) apk, use -t:
Run Build-Make Project
Look for the last generated apk in the app folder.
Example:
adb install -t C:\code\BackupRestore\app\build\outputs\apk\debug\app-debug.apk
You can do this by using adb command line tools OR gradle commands:
See this Guide.
Setup command line adb
export PATH=/Users/mayurik/Library/Android/sdk/platform-tools/adb:/Users/mayurik/Library/Android/sdk/tool
Gradle commands to build and install.
#Start Build Process
echo "\n\n\nStarting"
./gradlew clean
./gradlew build
./gradlew assembleDebug
#Install APK on device / emulator
echo "installDebug...\n"
./gradlew installDebug
You can also uninstall any previous versions using
`./gradlew uninstallDebug`
You can launch your main activity on device/emulator like below
#Launch Main Activity
adb shell am start -n "com.sample.androidbuildautomationsample/com.sample.androidbuildautomationsample.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
I use this script on my windows machine ( insall all apks in current folder to all available devices )
Write-Host "Listing APKs..."
$List_Apks = New-Object System.Collections.ArrayList
Get-ChildItem -Path .\ -Filter *.apk -File -Name| ForEach-Object {
$apk_filename = [System.IO.Path]::GetFileName($_)
$List_Apks+=$apk_filename
$apk_filename
}
Write-Host "Found apks "$List_Apks.Length
Write-Host ""
$raw_list = adb devices
$array_lines = $raw_list.Split("\n")
Write-Host "Listing devices "
$List_Device_Ids = New-Object System.Collections.ArrayList
1..($array_lines.Length-2) | foreach {
$device_id = $array_lines[$_].Split([char]0x9)[0]
$List_Device_Ids+=$device_id
$device_id
}
Write-Host "Found devices "$List_Device_Ids.Length
0..($List_Device_Ids.Length-1) | foreach {
$device_id = $List_Device_Ids[$_]
0..($List_Apks.Length-1) | foreach {
$apk_file_name = $List_Apks[$_]
Write-Host "Installing " $apk_file_name "->" $device_id
adb -s $device_id install -r $apk_file_name
}
}
Write-Host "Endo"
Save this as install-apks.ps1
Then from the powershell :
powershell -executionpolicy bypass -File .\install-apks.ps1
For people who wants to load apk from Linux system with React native application running on it.
I have given the path in which the android application resides as well. So that those who need to find the apk file can go to view it.
adb -s 434eeads install android/app/build/outputs/apk/debug/app-debug.apk
For reinstalling the android app on phone
adb -s 434eeads install -r android/app/build/outputs/apk/debug/app-debug.apk
-s -> source/serialNumber
r -> Re-install
path + file name : android/app/build/outputs/apk/debug/app-debug.apk
It is for react native applications.