I found that most released apps(including system apps) can be debugged on the emulator by the way following:
1. install the app on the emulator, and launch it
adb shell ps to get the pid of the app
adb jdwp, if you find the pid in the output, then you can attach to the app by running
adb forward tcp:1234 jdwp:$pid_you_find and
jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=1234
4. you can use commands such as "classes" to see the classes of the app, even "stop" to set breakpoint and "eval" to run many functions and see the members of the objects.
I have 2 questions:
1. Why these tricks fail on the phones? What's the difference between the rom of emulator and phones?
2. How to avoid my app being debugged through such way?