Error using command "adb install" or "adb push" :device offline - android

I'm using the AVD,I can use command "ls" to see files ,"adb remount" and it shows remount succeeded,but when using "adb push" , error:"device offline",and "Invalid APK file: 1.apk" when using command "adb install"
Here is the cmd output
D:\android-sdk\platform-tools>adb remount
remount succeeded
D:\android-sdk\platform-tools>adb shell
root#generic_x86_64:/ # adb install 1.apk
adb install 1.apk
Invalid APK file: 1.apk
255|root#generic_x86_64:/ # adb push 1.apk /sdcard
adb push 1.apk /sdcard
error: device offline
1|root#generic_x86_64:/ #
1|root#generic_x86_64:/ # ls
ls
acct
cache
charger
config
d
data

You need to execute "adb push" and "adb install" from your Windows command prompt, not inside the adb shell - the adb shell runs directly on your phone (emulator) and does not know about Windows.

Related

How to push a file from computer to /data/.../databases/ using adb command?

Below command is to pull a file:
adb -d shell "run-as com.myapp cat /data/data/com.myapp/databases/file.db" > file.db
But how to push it back like Android Studio does via Device File Explorer?
There is no simple command for uploading the file. What Android Studio does when uploading a file using Device File Explorer is this:
Upload the file via adb push to /data/local/tmp/<random file name>
Execute adb shell run-as com.myapp sh -c 'cp /data/local/tmp/<random file name> /data/data/com.myapp/<path>/<final file-name>'
Delete the temp file via adb shell rm /data/local/tmp/<random file name>
Get the updated view for Device File Explorer using adb shell run-as com.myapp sh -c 'ls -al /data/data/com.myapp/<path>/'
I discovered this by capturing the adb traffic on TCP port 5027 using Wireshark. An interesting detail is that each command executed using adb shell command uses the form <command-to-be executed in adb shell> || echo ERR-ERR-ERR-ERR
From Robert's answer now I can do like this:
function dbpull() {
adb shell run-as "com.$1.debug" cat "/data/data/com.$1.debug/databases/$2.db" > "/Users/username/Desktop/$2.db"
}
function dbpush() {
adb push "/Users/username/Desktop/$1.db" "/sdcard/db/tmp/"
}
function dbpush2() {
adb shell run-as "com.$1.debug" cp "/sdcard/db/tmp/$2.db" "/data/data/com.$1.debug/databases/$2.db"
}
function dbcheck() {
adb shell run-as "com.$1.debug" ls -al "/data/data/com.$1.debug/databases/"
}
Just write above code lines in your .bash_profile and then call it in terminal.
dbpull myapp mydata
At this moment I prefer to use Visual Studio Code than Android Studio to develop my Android apps. So, I need to know more about commands in terminal, e.g. adb, gradle, etc.
I hope this would be useful for everyone.
Use this command
adb push <file_path> <android_device_path>
adb pull <android_device_path>

'Error=2, No such file or directory' error in android adb shell

Save the file on the web to cacheDir and run it as follows.
'error=2, No such file or directory' error occurs
If you go to the folder in the terminal, the file is there and the permissions are OK.
What is the problem?
adb install -r /data/user/0/pakagename/cache/app.apk
adb install will install files in your local PC.
You should use:
# enter shell on the device
adb shell
# execute in device
pm install /data/user/0/pakagename/cache/app.apk
Or use one command:
adb shell pm install /data/user/0/pakagename/cache/app.apk

How to copy a file to Android's /system folder

I am running Android emulator (emulator version 30.5.5.0) and the avd: Pixel_3a_API_30_x86 from AndroidStudio.
Using adb.exe (Android Debug Bridge) I try to copy a file from the Windows host to the emulated Android /system/... folder, but I haven't been able to after trying different things like this tutorial:
I run the android emulator from the command line to specify the parameter -writable-system:
cd C:\Users\%username%\AppData\Local\Android\Sdk\emulator
emulator -avd Pixel_3a_API_30_x86 -writable-system
Then from another command-line window while the emulator is running:
cd C:\Users\%username%\AppData\Local\Android\Sdk\platform-tools
adb root
adb shell "mount -o rw,remount /"
'/dev/block/dm-0' is read-only
adb push MyFile.txt /system/etc/security/cacerts
Then I get the error:
ERROR:
MyFile.txt: 1 file pushed, 0 skipped. 0.1 MB/s (950 bytes in 0.011s)
adb: error: failed to copy 'MyFile.txt' to '/system/etc/security/cacerts/MyFile.txt': remote couldn't create file: Read-only file system
How can I copy the file from Windows to Android /system ?
The tutorial in the link was missing some commands and the web page was not updated with the latest version from GitHub.
Here is the final sequence (for API LEVEL > 28):
adb root
adb shell avbctl disable-verification
adb reboot
adb root
adb remount
adb push MyFile.txt /system/etc/security/cacerts
Run adb root && adb remount first.

Edit marshmallow hosts file

I'm trying to edit the hosts file on the Marshmallow emulator, but I can't do it. I use ADB tool:
I start emulator using emulator.exe
adb mount
adb pull /system/etc/hosts c:\temp
Then I edit hosts file
ADB push c:\temp\hosts /system/etc (this step doesn't work, because I get error - "read-only file system").
Also, I tried to do adb shell and then SU commands and then mount -o rw,remount /system. But every time when I try to edit hosts file, I get the error that file system is read only.
Any ideas?
Try this for the remount:
adb shell
setenforce 0
mount -o rw,remount /system
setenforce 1
These steps work for me (Windows 8.1 and Android Studio emulator (qemu))
Open a Command Prompt
cd %localappdata%\Android\sdk\tools
Run the emulator from the command line with -writable-system flag, e.g.
emulator -avd (your AVD name) -writable-system
While the emulator is booting (wait until the Android splash appears):
cd %localappdata%\Android\sdk\platform-tools
adb root (do not proceed until this command has been successful)
adb remount
adb push c:\temp\hosts /system/etc/hosts

ADB Batch Script

I really need some help with my syntax and getting this to run right. So im trying to automate an entire kodi, and llama install just by entering your ip into a batch file. Any assistance would be much appreciated.
cls
echo.
echo You will install an app
echo The app need to be in your ADB-Folder
echo Before you hit enter INSTALL "iKoNo"" on your FireTV
echo.
pause
echo.
echo You can find your IP by going to Settings > About > Network on your device
set /p ip=Enter the IP of your FireTV or FireTVStick:
adb kill-server
adb connect 192.168.137.%ip%
adb install "%UserProfile%\Desktop\FireTV\kodi.apk"
adb install "%UserProfile%\Desktop\FireTV\settings.apk"
adb install "%UserProfile%\Desktop\FireTV\llama.apk"
adb push "%UserProfile%\Desktop\FireTV\busybox" /data/local/tmp/
adb shell chmod 755 /data/local/tmp/busybox
adb shell "%UserProfile%\Desktop\FireTV\busybox" --install -s /data/local/tmp
adb push "%UserProfile%\Desktop\FireTV\adbfw128\events\llamakodi\linkiko" /sdcard/Llama/
adb push "%UserProfile%\Desktop\FireTV\adbfw128\events\llamakodi\linkiko\Llama_Profiles.txt" -> /sdcard/Llama/Llama_Profiles.txt
adb push "%UserProfile%\Desktop\FireTV\adbfw128\events\llamakodi\linkiko\Llama_NfcNames.txt" -> /sdcard/Llama/Llama_NfcNames.txt
adb push "%UserProfile%\Desktop\FireTV\adbfw128\events\llamakodi\linkiko\Llama_IgnoredCells.txt" -> /sdcard/Llama/Llama_IgnoredCells.txt
adb push "%UserProfile%\Desktop\FireTV\adbfw128\events\llamakodi\linkiko\Llama_Events.txt" -> /sdcard/Llama/Llama_Events.txt
adb push "%UserProfile%\Desktop\FireTV\adbfw128\events\llamakodi\linkiko\Llama_Areas.txt" -> /sdcard/Llama/Llama_Areas.txt
adb shell rm -r /sdcard/.imagecache/com.amazon.venezia/org.ikonotv.smarttv
adb shell mkdir -p /sdcard/.imagecache/com.amazon.venezia/org.ikonotv.smarttv
adb push "%UserProfile%\Desktop\FireTV\adbfw128\icons\ikokodi.icon" /sdcard/.imagecache/com.amazon.venezia/org.ikonotv.smarttv
adb push "%UserProfile%\Desktop\FireTV\adbfw128\icons\ikokodi.icon\B00NEJS7ZO\thumbnail_bfc0289736b3b0fbd3e32dec9d5d44c9dbe7cef5a082645ab0af157c6f3f600b.png" -> /sdcard/.imagecache/com.amazon.venezia/org.ikonotv.smarttv/B00NEJS7ZO/thumbnail_bfc0289736b3b0fbd3e32dec9d5d44c9dbe7cef5a082645ab0af157c6f3f600b.png
adb push "%UserProfile%\Desktop\FireTV\adbfw128\icons\icons\ikokodi.icon\B00NEJS7ZO\preview_5dd7e33b605bec171c4bba546e5b35c783feb32a53c44227249ad52f653dc49c.png" -> /sdcard/.imagecache/com.amazon.venezia/org.ikonotv.smarttv/B00NEJS7ZO/preview_5dd7e33b605bec171c4bba546e5b35c783feb32a53c44227249ad52f653dc49c.png
adb kill-server
echo.
echo Done!
for some reason its not working right im trying to use the same process adbfire does!
In this code --> https://github.com/Jocala/adbFire/blob/master/mainwindow.cpp
The > symbols in your batch file are interpreted by CMD.exe as redirection of output to a file. Escape them with ^ so each -> should be written as -^> if you need this symbol passed as a parameter.
However ADB PUSH local_file remote_file syntax doesn't require use of these symbols, so just don't use -> at all.

Categories

Resources