Related
Anyone know how to edit /etc/hosts file inside an android studio emulator running in nougat? I will be editing it so I can use my virtual host in my local web server. I tried editing it through terminal using adb however, it is returning Read-only file system. Tried also using chmod but still it fails.
Update:
I also tried pulling and pushing files using adb
$ ./adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts
adb: error: failed to copy '/Users/Christian/Desktop/hosts' to '/system/etc/hosts': couldn't create file: Read-only file system
1) android-sdk-macosx/tools/emulator -avd <avdname> -writable-system
2) ./adb root
3) ./adb remount
4) ./adb push <local>/hosts /etc/hosts
Android file host can be
/etc/hosts <--- This worked for me
/etc/system/hosts
/system/etc/hosts
Check
1) ./adb shell
2) cat /etc/hosts
3) ping customsite.com
Step by Step
Don’t Create the AVD with a Google Play image.
Use for example Google APIs Intel x86 Atom System Image.
Start the emulator with the following command…
emulator.exe –avd <avd name> -writable-system
For example:
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\emulator>emulator.exe -avd Pixel_API_25 -writable-system
emulator: WARNING: System image is writable
HAX is working and emulator runs in fast virt mode.
audio: Failed to create voice `goldfish_audio_in'
qemu-system-i386.exe: warning: opening audio input failed
audio: Failed to create voice `adc'
Root and Remount the AVD like the followings…
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb root
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb remount
remount succeeded
C:\Users\ilyas.mamun\AppData\Local\Android\Sdk\platform-tools>adb shell
eneric_x86:/ # cd system
generic_x86:/system # cd etc
generic_x86:/system/etc # cat hosts
127.0.0.1 localhost
::1 ip6-localhost
generic_x86:/system/etc # echo "192.168.1.120 ilyasmamun.blogspot.com" >> hosts
generic_x86:/system/etc # cat hosts
127.0.0.1 localhost
::1 ip6-localhost
192.168.1.120 ilyasmamun.blogspot.com
generic_x86:/system/etc #
Here is how i was able to do it working on OSX. After reading a bunch of different instruction nothing seemd to work for me untill someone mentioned that you have a very narrow window for copying the file from your disk to the emulated device or it becomes read-only again
Start your emulator.
In your terminal find the folder "platform-tools" for your devices
Prepare the hosts file you want to copy to your device (in my case i put it on desktop)
String together a bunch of commands to copy the file quickly. This is what worked for me ./adb root && ./adb -s emulator-5554 remount && ./adb -s emulator-5554 push ~/Desktop/hosts /system/etc/hosts 'emulator-5554' is the name of my device which you can find by typing ./adb devices
after that the terminal responded with
restarting adbd as root
remount succeeded
[100%] /system/etc/hosts
you can veryfy the copy was successfull by ./adb shell and then cat /system/etc/hosts
I was then able to connect to my virtual hosts from the emulated device
Just to be complete here is how my hosts file looked like
10.0.2.2 my-virtual-host
I hope this helps someone as i spet quite some time trying to figure this out.
Below are the steps I followed on my Windows machine on Windows Terminal:
Run the following command to know your AVDs:
emulator -list-avds
Run the following command to open the emulator for writable mode:
emulator -avd Pixel_XL_API_29 -writable-system -no-snapshot-load
Replace Pixel_XL_API_29 with your AVD name.
Ignore the warnings there.
In a new Terminal tab run the following commands:
adb root
adb shell avbctl disable-verification
adb reboot
Wait for your emulator to reboot. It can take upto 1 minute.
When the emulator is rebooted, run the following commands:
adb root
adb remount
You will get a remount succeeded message after that:
Now is the time to push our host file from Windows machine to Android's emulator
adb push D:\hosts /system/etc/
D:\hosts is the location of the hosts file present at the D drive of my Windows machine.
/system/etc/ is the location in Android's emulator where we want to copy that file.
After successfull operation you will see a message like this:
To verify that the hosts file has been pushed you can run the following commands:
adb shell
cd system
cd etc
cat hosts
You will see the contents of hosts file in the Terminal:
I was able to edit the /etc/hosts file by launching the emulator with -writable-system and remounting the emulator using adb remount. After that the hosts file inside the emulator is editable. I tried pushing/replacing the file and succeeded.
Another approach to this matter would be to use the adb command line tool.
Make sure you have in path emulator and tools
export ANDROID_HOME="/Users/YOUR_USERNAME/Library/Android/sdk"
export PATH=$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$PATH
EDIT: For Windows should something like this (instead of tools required platform-tools [or the path where adb resides])
C:\Users\YOUR_USERNAME\AppData\Local\Android\sdk\platform-tools
C:\Users\YOUR_USERNAME\AppData\Local\Android\sdk\emulator
Check device name (ideally it would be to have a short name without spaces, eg. API30X86)
emulator -list-avds
Then launch the emulator with the following arguments:
emulator -avd YOUR_AVD_NAME -writable-system -no-snapshot-load -no-cache
Run the following commands to run as root and remount the partition system as root
adb devices #you should see your devices
adb root
adb shell avbctl disable-verification
adb reboot
adb root
adb remount
After remount, you should be able to push the edited host file from your machine to the emulator.
adb push ~/Documents/hostsandroid /etc/hosts
Now you should be able to see your hosts file with Device File Explorer from Android Studio.
EDIT: In the case, you don’t see the Device File Explorer, you can check the Event Log if Android framework is detected. If so, click Configure and you're done.
When you are going to run again and push new changes with a new session, you’ll only have to do:
adb root
adb remount
adb push ~/Documents/hostsandroid /etc/hosts
Follow the below 3 steps :
Start emulator in writable mode : ./emulator -avd <emulator_name> -writable-system
remount : adb remount
push the hosts file attached : adb push hosts /system/etc/
Note :
Run one and only one emulator_name with above steps
executable emulator is located within android-sdk. For me it was under sdk/emulator.
Attached hosts file will resolve www.facebook.com to 127.0.0.1, hence blocks www.facebook.com on emulator.
First find your system hosts file and copy it to desktop
Then create a virtual device Nexus 5 with system image Nougat x86_64 Android 7.1.1 (non Google API version) once it is created
Then goto /Android/sdk/emulator in terminal then run the below code please add your own device name below as mine was Nexus_S_API_25 =>
./emulator -writable-system -netdelay none -netspeed full -avd Nexus_S_API_25
After that Open a new terminal and goto this location
/Android/sdk/platform-tools
then run
./adb root
./adb remount
./adb push ~/Desktop/hosts /system/etc/hosts - (It will copy your Desktop/hosts file and paste it into your emulator hosts file which is /system/etc/hosts)
That's it your emulator hosts file is updated Now if you want to re-check then run the below code
./adb shell
cat /system/etc/hosts (it will show you the emulator hosts file)
Restart the emulator to see the changes
./adb reboot
Tedious, but effective, you can build a new hosts file, line by line within your emulator shell.
Remount Emulator
You can edit/remount your emulator (to get a writeable filesystem) in your PC/Mac/linux command line / powershell / terminal.
(Stop your emulator if it's already running, then...):
emulator -avd <avdname> -writable-system
(this starts up a new emulator with a writable file system)
Still within your PC/Mac/Linux terminal run these two commands:
adb root
adb remount
Then connect to your running emulator via a shell:
adb shell
This part below is run from inside your emulator, inside the shell connection you just made.
Give yourself root access:
su
Change directory to where the hosts file is kept:
cd /etc
To make your emulator defer to your development machine's hosts file or DNS for a given domain, add a domain entry using ip of 10.0.2.2.
Example of appending a new domain entry line to emulator hosts file:
echo '10.0.2.2 mydev.domain.com' >> hosts
This 10.0.2.2 is a special address for Android emulators. It will proxy DNS requests for that domain to your development machine. So whatever IP address your PC/Mac/Linux machine hosts file lists for mydev.domain.com, the Android emulator will use it.
You can now exit the root shell & your emulator shell:
exit
exit
(1st gets you out of su. 2nd exits from the emulator shell, dropping you back into your development machine's terminal).
You're done. You can open up a web browser inside your emulator, type the domain you just added to hosts into the address bar and check the emulator is routing that domain properly.
Remount failed
If you're on Android emulator 29+ and getting
remount failed
when calling adb remount, check out the workaround by Kidd Tang here.
You can use the ADB Shell to edit the file by changing the access (Read Only to RW)
Try #P.O.W answer,
Make sure you have a blank line after the last entry of the hosts file
If you use tabs in the hosts file, replace them with spaces
Restart Android and try again:
adb reboot
place all these export in z shell using terminal
vim ~/.zshrc press enter
then zshell will open
then press i
past all the export (verify the path i have used all default location for instalation)
then press esc
then press this :wq!
press enter
close terminal and open it again
export PATH="$PATH:$HOME/Dev/flutter/bin"
export GEM_HOME=$HOME/.gem
export PATH=$GEM_HOME/bin:$PATH
export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
only use google apis image do not usese play image
u will get list of avds
emulator -list-avds
emulator -avd Nexus_5_API_29 -writable-system (do not close terminal) (open a new terminal)
adb root
adb remount
copy mac host file to Downloads from /private/etc/hosts
adb push Downloads/hosts /system/etc/hosts
adb reboot
I need remote ADB shell..
I know that we have to issue "ADB tcpip ".. to change ADB server to TCP listening mode.
But, the problem is that my phone is not rooted, and I do not have USB cable.
I can't issue tcpip command since I do not have USB cable,,
I can't change default.prop file as the phone is not rooted.
Is there any other ways to change ADB server to TCP listening mode???
I found an articel that says you can execute setprop persist.adb.tcp.port 5555 to make tcpip mode autostart after reboot.
The problem is, you must run this command as root.
On my device unfortunally the command su doeas not exist.
Here is the orginal Permanent network debugging on android
EDIT: I discovered, that the su command is only available when your device is rooted.
So the solution only works when you have a rooted phone
The simple answer is: no, you can't.
As you said, you can't access the prop file and don't have a cable to change with ADB. The only way is you find the port via an Android terminal emulator (a.k.a Termux)
For anyone looking for a better answer:
YES, YOU CAN!!
When you try to execute "adb tcpip 5555" without an USB cable, it returns:
"error: no devices/emulators found"
Emulators?? After googling I found the way and made a batch file that connects my device directly through WIFI, no cables needed at all:
set /p ip= Device IP:
:CONNECT
if "%CD%"=="C:\" goto ROOT
cd ..
goto CONNECT
:ROOT
cd ...Android\Sdk\emulator
echo.
echo Starting emulator...
start /MIN emulator -avd Nexus_5X_API_29_x86 -no-window
(you can check other avaliable devices with "emulator -list-avds")
cd ..
cd platform-tools
adb wait-for-device
echo.
echo Emulator started.
echo Connecting with device...
adb tcpip 5555
adb connect %ip%
echo.
echo Closing emulator...
(you need it just to be able to execute "adb tcpip 5555")
adb -s emulator-5554 emu kill
(you can check the name with "adb devices")
To enable wireless debug need to configure the ADB command. (in mac os)
Step1:- First of all need to enable adb command. (check SDK tool and install command-line tools)
Step2:- connect the device with a USB cable after that run the below command.
command: adb devices
the above command will show a list of connected mobiles.
Step3:- after that, we need to configure TCPIP protocol:
e.g : adb tcpip 5556
Step4:- Run command to connect the device.
command: adb connect your_ip:port_address
eg:- adb connect 192.168.1.152:5556
If you are using the stock android os system, then you can enable remote debugging in Settting -> developer options.
I want to save the screenshot created, in a specific folder on my PC.
cmd = 'adb shell screencap -p /sdcard/screen.png'
subprocess.Popen(cmd.split())
time.sleep(5)
cmd ='adb pull /sdcard/screen.png screen.png'
subprocess.Popen(cmd.split())
This works if I want the image in my workspace. But if I want to pull the screenshot in another folder, it doesn't work.
cmd ='adb pull /sdcard/screen.png C:\Users\xxx\Desktop\prova\screen.png'
subprocess.Popen(cmd.split())
if i run the command from cmd i have:
Android Debug Bridge version 1.0.31
-d - directs command to the only connected USB device
returns an error if more than one USB device is present.
-e - directs command to the only running emulator.
returns an error if more than one emulator is running.
-s <specific device> - directs command to the device or emulator with the given
serial number or qualifier. Overrides ANDROID_SERIAL
environment variable.
-p <product name or path> - simple product name like 'sooner', or
a relative/absolute path to a product
out directory like 'out/target/product/sooner'.
If -p is not specified, the ANDROID_PRODUCT_OUT
environment variable is used, which must
be an absolute path.
devices [-l] - list all connected devices
('-l' will also list device qualifiers)
connect <host>[:<port>] - connect to a device via TCP/IP
Port 5555 is used by default if no port number is specified.
disconnect [<host>[:<port>]] - disconnect from a TCP/IP device.
Port 5555 is used by default if no port number is specified.
Using this command with no additional arguments
will disconnect from all connected TCP/IP devices.
device commands:
adb push <local> <remote> - copy file/dir to device
adb pull <remote> [<local>] - copy file/dir from device
adb sync [ <directory> ] - copy host->device only if changed
(-l means list but don't copy)
(see 'adb help all')
adb shell - run remote shell interactively
adb shell <command> - run remote shell command
adb emu <command> - run emulator console command
adb logcat [ <filter-spec> ] - View device log
adb forward <local> <remote> - forward socket connections
forward specs are one of:
tcp:<port>
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)
adb jdwp - list PIDs of processes hosting a JDWP transport
adb install [-l] [-r] [-s] [--algo <algorithm name> --key <hex-encoded key> --iv <hex-encoded iv>] <file>
- push this package file to the device and install it
('-l' means forward-lock the app)
('-r' means reinstall the app, keeping its data)
('-s' means install on SD card instead of internal storage)
('--algo', '--key', and '--iv' mean the file is encrypted already)
adb uninstall [-k] <package> - remove this app package from the device
('-k' means keep the data and cache directories)
adb bugreport - return all information from the device
that should be included in a bug report.
adb backup [-f <file>] [-apk|-noapk] [-shared|-noshared] [-all] [-system|-nosystem] [<packages...>]
- write an archive of the device's data to <file>.
If no -f option is supplied then the data is written
to "backup.ab" in the current directory.
(-apk|-noapk enable/disable backup of the .apks themselves
in the archive; the default is noapk.)
(-shared|-noshared enable/disable backup of the device's
shared storage / SD card contents; the default is noshared.)
(-all means to back up all installed applications)
(-system|-nosystem toggles whether -all automatically includes
system applications; the default is to include system apps)
(<packages...> is the list of applications to be backed up. If
the -all or -shared flags are passed, then the package
list is optional. Applications explicitly given on the
command line will be included even if -nosystem would
ordinarily cause them to be omitted.)
adb restore <file> - restore device contents from the <file> backup archive
adb help - show this help message
adb version - show version num
scripting:
adb wait-for-device - block until device is online
adb start-server - ensure that there is a server running
adb kill-server - kill the server if it is running
adb get-state - prints: offline | bootloader | device
adb get-serialno - prints: <serial-number>
adb get-devpath - prints: <device-path>
adb status-window - continuously print device status for a specified device
adb remount - remounts the /system partition on the device read-write
adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program
adb reboot-bootloader - reboots the device into the bootloader
adb root - restarts the adbd daemon with root permissions
adb usb - restarts the adbd daemon listening on USB
adb tcpip <port> - restarts the adbd daemon listening on TCP on the specified port
networking:
adb ppp <tty> [parameters] - Run PPP over USB.
Note: you should not automatically start a PPP connection.
<tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
[parameters] - Eg. defaultroute debug dump local notty usepeerdns
adb sync notes: adb sync [ <directory> ]
<localdir> can be interpreted in several ways:
- If <directory> is not specified, both /system and /data partitions will be updated.
- If it is "system" or "data", only the corresponding partition
is updated.
environmental variables:
ADB_TRACE - Print debug information. A comma separated list of the following values
1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp
ANDROID_SERIAL - The serial number to connect to. -s takes priority over this if given.
ANDROID_LOG_TAGS - When used with the logcat option, only these debug tags are printed.
What can I do?
Always use double quotes("") for local paths. use it like this:
cmd = "adb pull /sdcard/screen.png \"C:\\Users\\xxx\\Desktop\\prova\\screen.png\"";
Don't write file name in destination path.
write in specific command like this:
adb pull
for example :
adb pull /sdcard/pictures c:/users/intel1/desktop/newfolder
This version worked for me
adb pull /sdcard/demo.mp4 "C:\Users\xxxxxxx\Desktop"
The one by #M D P did not as all those double dashes were unnecessary.
so, i'm trying to push some files to /system on android device (zte)
I've rooted, connected with ADB,
adb remount -> I get permission denied
adb shell su -> I'm able to access shell and create folders etc and edit filesystem
(but in shell I can't copy a file from my computer to device)
Any help please
In case anyone has the same problem in the future:
$ adb shell
$ su
# mount -o rw,remount /system
Both adb remount and adb root don't work on a production build without altering ro.secure, but you can still remount /system by opening a shell, asking for root permissions and typing the mount command.
emulator -writable-system
For people using an Emulator: Another possibility is that you need to start the emulator with -writable-system. That was the only thing that worked for me when using the standard emulator packaged with android studio with a 4.1 image. Check here: https://stackoverflow.com/a/41332316/4962858
Try
adb root
adb remount
to start the adb demon as root and ensure partitions are mounted in read-write mode (the essential part is adb root). After pushing, revoke root permissions again using:
adb unroot
Some newer builds require the following additional adb commands to be run first
adb root
adb disable-verity
adb reboot
Then
adb root
adb remount
you can use:
adb shell su -c "your command here"
only rooted devices with su works.
Start /w Writable System
Using Emulator Images without Google Play
This does not work with production Android images, i.e. ones with Google Play
Use non-Google Play images for root access & writeable system
Start your emulator from a command prompt as a writable system, using its AVD Name (Pixel3a in this example, see AVD Name below to find or change yours. Make sure another emulator instance is not running when using this command):
emulator #Pixel3a -writable-system
(Keep this command handy. You will need to use it any time you want to access your emulator as 'writable'. I use an alias in gitbash to start my emulator from a gitbash terminal, everytime.)
This launches the emulator.
When startup is complete, open another command prompt/terminal (this one is stuck running the emulator) and:
adb root
Result should be:
$ adb root
restarting adbd as root
Then:
adb remount
Result:
$ adb remount
remount succeeded
When you:
adb shell
and:
su
You should now have full root/writable access:
$ adb shell
generic_x86_arm:/ # su
generic_x86_arm:/ #
To add a domain to hosts file
$ cd /etc
$ cp hosts hosts.bak1
$ cat hosts
127.0.0.1 localhost
::1 ip6-localhost
$ echo '10.0.2.2 my.newdomain.com' >> hosts
$ cat hosts
127.0.0.1 localhost
::1 ip6-localhost
10.0.2.2 my.newdomain.com
10.0.2.2 is "localhost" for an Android emulator. It will delegate to your Windows/Mac hosts file & DNS services. Any domain you add to your development machine's hosts file, will work as 10.0.2.2 on your Android Emulator hosts file.
AVD Name
In Android Studio AVD Manager can be launched from menu:
Tools > AVD Manager
If your emulator name has spaces, you can change that by clicking the pencil icon on right hand side.
I named my emulator 'Pixel3a' without spaces for ease of typing.
I rebooted to recovery
then
adb root; adb adb remount system;
worked for me
my recovery is twrp v3.5
Try with an API lvl 28 emulator (Android 9).
I was trying with api lvl 29 and kept getting errors.
#echo off
color 0B
echo =============================================================================
echo.
echo ClockworkMod Recovery for SAMSUNG GALAXY SIII E210L
echo.
echo ClockworkMod Recovery (v6.0.1.2 Touch)
echo.
echo ¡ô¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¡ô
echo ¨U ¨U
echo ¨U SAMSUNG GALAXY SIII E210L ¨U
echo ¡ô¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¨T¡ô
echo.
echo 1) (Settings\Developer options©¥ USB debugging)
echo.
echo 2) CWM SAMSUNG GALAXY SIII E210L
echo.
echo 3) THANK!!!!!!
echo.
echo =============================================================================
echo ARE YOU READY? GO! ¡·¡·¡·
#pause
echo.
echo adb...
adb.exe kill-server
adb.exe wait-for-device
echo wiat¸!
echo.
echo conect...
adb.exe push IMG /data/local/tmp/
adb.exe shell su -c "dd if=/data/local/tmp/GANGSTAR-VEGAS-1.3.0-APK-Andropalace.net.apk of=/mnt/sdcard/Android/GANGSTAR-VEGAS-1.3.0-APK-Andropalace.net.apk
adb.exe shell su -c "rm /data/local/tmp/bootloader.img"
adb.exe shell su -c "rm /data/local/tmp/recovery.img"
echo ===============================================================
echo ClockworkMod Recovery!
echo.
#pause
I'm trying to perform native code debug on my HTC Desire for my Android project.
The project is made of a thin layer of JNI wrapper and the main chunk in C++, compiled using ndk-build. The debuggable flag is set, I'm running 2.2 on an HTC Desire and I'm working with Ubuntu on my PC.
So a plain ndk-gdb --start returns a:
ERROR: Could not setup network redirection to gdbserver?
Maybe using --port=<port> to use a different TCP port might help?
This is weird. I checked on the internet and found that it's the wrong message error caused by a flaw in ndk-gdb. If I run ndk-gdb -- start --verbose I obtain this messed up error:
Android NDK installation path: /home/marco/dev/android-ndk
Using specific adb command: /home/marco/dev/android-sdk//platform-tools/adb
ADB version found: Android Debug Bridge version 1.0.26
Using final ADB command: '/home/marco/dev/android-sdk//platform-tools/adb'
Using auto-detected project path: .
Found package name: com.marco83.siege
ABIs targetted by application: armeabi
Device API Level: 8
Device CPU ABIs: armeabi-v7a armeabi
Compatible device ABI: armeabi
Found debuggable flag: true
Found device gdbserver: /data/data/com.marco83.siege/lib/gdbserver
Using gdb setup init: /home/marco/dev/siege_game/trunk/SiegeGameNative/libs/armeabi/gdb.setup
Using toolchain prefix: /home/marco/dev/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-
Using app out directory: /home/marco/dev/siege_game/trunk/SiegeGameNative/obj/local/armeabi
Found data directory: 'run-as: Package 'com.marco83.siege' has corrupt installation'
Found first launchable activity: .Main
Launching activity: com.marco83.siege/.Main
## COMMAND: /home/marco/dev/android-sdk//platform-tools/adb shell am start -n com.marco83.siege/.Main
Starting: Intent { cmp=com.marco83.siege/.Main }
Warning: Activity not started, its current task has been brought to the front
## COMMAND: /home/marco/dev/android-sdk//platform-tools/adb shell sleep 2
Found running PID: 844
Launched gdbserver succesfully.
Setup network redirection
## COMMAND: /home/marco/dev/android-sdk//platform-tools/adb forward tcp:5039 localfilesystem:run-as: Package 'com.marco83.siege' has corrupt installation/debug-socket
## COMMAND: /home/marco/dev/android-sdk//platform-tools/adb shell run-as com.marco83.siege lib/gdbserver +debug-socket --attach 844
Android Debug Bridge version 1.0.26
-d - directs command to the only connected USB device
returns an error if more than one USB device is present.
-e - directs command to the only running emulator.
returns an error if more than one emulator is running.
-s <serial number> - directs command to the USB device or emulator with
the given serial number. Overrides ANDROID_SERIAL
environment variable.
-p <product name or path> - simple product name like 'sooner', or
a relative/absolute path to a product
out directory like 'out/target/product/sooner'.
If -p is not specified, the ANDROID_PRODUCT_OUT
environment variable is used, which must
be an absolute path.
devices - list all connected devices
connect <host>[:<port>] - connect to a device via TCP/IP
Port 5555 is used by default if no port number is specified.
disconnect [<host>[:<port>]] - disconnect from a TCP/IP device.
Port 5555 is used by default if no port number is specified.
Using this ocmmand with no additional arguments
will disconnect from all connected TCP/IP devices.
device commands:
adb push <local> <remote> - copy file/dir to device
adb pull <remote> [<local>] - copy file/dir from device
adb sync [ <directory> ] - copy host->device only if changed
(-l means list but don't copy)
(see 'adb help all')
adb shell - run remote shell interactively
adb shell <command> - run remote shell command
adb emu <command> - run emulator console command
adb logcat [ <filter-spec> ] - View device log
adb forward <local> <remote> - forward socket connections
forward specs are one of:
tcp:<port>
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)
adb jdwp - list PIDs of processes hosting a JDWP transport
adb install [-l] [-r] [-s] <file> - push this package file to the device and install it
('-l' means forward-lock the app)
('-r' means reinstall the app, keeping its data)
('-s' means install on SD card instead of internal storage)
adb uninstall [-k] <package> - remove this app package from the device
('-k' means keep the data and cache directories)
adb bugreport - return all information from the device
that should be included in a bug report.
adb help - show this help message
adb version - show version num
DATAOPTS:
(no option) - don't touch the data partition
-w - wipe the data partition
-d - flash the data partition
scripting:
adb wait-for-device - block until device is online
adb start-server - ensure that there is a server running
adb kill-server - kill the server if it is running
adb get-state - prints: offline | bootloader | device
adb get-serialno - prints: <serial-number>
adb status-window - continuously print device status for a specified device
adb remount - remounts the /system partition on the device read-write
adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program
adb reboot-bootloader - reboots the device into the bootloader
adb root - restarts the adbd daemon with root permissions
adb usb - restarts the adbd daemon listening on USB
adb tcpip <port> - restarts the adbd daemon listening on TCP on the specified port
networking:
adb ppp <tty> [parameters] - Run PPP over USB.
Note: you should not automatically start a PPP connection.
<tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
[parameters] - Eg. defaultroute debug dump local notty usepeerdns
adb sync notes: adb sync [ <directory> ]
<localdir> can be interpreted in several ways:
- If <directory> is not specified, both /system and /data partitions will be updated.
- If it is "system" or "data", only the corresponding partition
is updated.
environmental variables:
ADB_TRACE - Print debug information. A comma separated list of the following values
1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp
ANDROID_SERIAL - The serial number to connect to. -s takes priority over this if given.
ANDROID_LOG_TAGS - When used with the logcat option, only these debug tags are printed.
ERROR: Could not setup network redirection to gdbserver?
Maybe using --port=<port> to use a different TCP port might help?
marco#pacer:~/dev/siege_game/trunk/SiegeGameNative$ run-as: Package 'com.marco83.siege' has corrupt installation
which, as you can see and as reported here: http://vilimpoc.org/blog/2010/09/23/hello-gdbserver-a-debuggable-jni-example-for-android/ is caused by a mix of different simultaneous outputs; the real error should be
Package 'xxxxx' has corrupt installation
Further investigation in this error pointed me to: http://osdir.com/ml/android-ndk/2010-08/msg00263.html
where the same error is reported, and they say it's not possible to debug natively on Desire. The problem is with run-as not being able to access the /data folder.
Any solution other than rooting/flashing the phone? Why does the run-as access /data?
I was thinking of a naive solution where I copy the package (objs, libs, ...) into an easier accessible location (like on the SDcard) and tell the debugger to access that location instead - is it feasible?
Thanks
Marco
EDIT: Update: I rooted the phone using unrevoked3. Even if I set chmod 0777 data (which is probably EXTREMELY dangerous), I get the same error. As reported in the second link in the post, run-as is checking if /data is accessible. How can I access run-as source code? Is it possible to recompile it and upload a modified version that works around this check? (since I can set /data to be readable by everyone anyway)
I fixed this issue for a HTC Desire S (2.3.3) by changing access & ownership for directory '/data/data':
Before the fix:
ls -l /data
(...)
drwxrwxrwx root root 2012-03-03 19:07 data
In root mode:
chmod 771 /data/data
chown system.system /data/data
ls -l /data
(...)
drwxrwx--x system system 2012-03-03 19:07 data
Also the /data director may need changing.
chmod 771 /data
chown system.system /data
Have same problem with my HTC Legend. My workaround:
get root access
get PID of app you want to debug: ps | grep your_app_package
run gdb server: /data/data/your_app_package/lib/gdbserver :5039 --attach PID
in new terminal
adb forward tcp:5039 tcp:5039
adb pull system/bin/app_process project_path/obj/local/armeabi/app_process
adb pull system/bin/libc.so /project_path/obj/local/armeabi/libc.so
Now you can connect to gdbserverb (http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-debugging/#more-23 skip steps with ndk-gdb).
PS: dont forget compile your code with following flags
LOCAL_CFLAGS := -g #debug
LOCAL_LDFLAGS := -Wl,-Map,xxx.map #create map fil
Stumbled upon this thread: http://code.google.com/p/android/issues/detail?id=16391
Solved run-as issue for me, ndk-gdb now works properly.
I used to get this problem, until I changed the package name to be 4 nested instead of 3. Don't know why that is an issue (already emailed the developers about it) but if your package name is a.b.c only the java debugger works. For native debugging it needs to be in the form of a.b.c.d.
The path /should/ be correct (both "data" directories are 771 and
system:system, the app's data directory is 755 and owned by an "app_"
account).
u need s-on turn to s-off (firmware)
for tegra 3 chip s-off
http://bbs.angeeks.com/thread-2598143-1-1.html
///
for Qualcomm chip s-off
bbs.htc.com/cn/thread-11592-1-1.html
I have 2 HTC phones, Sensation s-off, One X s-on
Sensation can use ndk debug, but One X can not.
here is photo left is Sensation, right is One X
https://plus.google.com/photos/106185541018774360364/albums/6156448731748249457/6156448735435939234?banner=pwa&sort=1&pid=6156448735435939234&oid=106185541018774360364