Android developers a common method and order

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/myvest/article/details/91411708

1, APK common debug commands

am command

1) Start a apk
way to start is
am start -n package (package) name / activity (activity) full path
such as:
am start -n com.android.music / com.android.music.VideoBrowserActivity
or am start -n com.android.music / .VideoBrowserActivity
AM start -a action
can specify the action to start the apk

But when you do not know Activity, Monkey 1 -p package name , you can also start APK
2 sends the specified broadcast):
AM Broadcast -a xxx broadcast
as Power Radio:
AM Broadcast -a android.intent.action.BOOT_COMPLETED

dumpsys command

Gets the currently focused Activity
dumpsys Activity | grep "mFocusedActivity"

Get the current top Activity
dumpsys Activity | grep -i "Top"

Check the Android system broadcasts recorded
dumpsys | grep BroadcastRecord

View apk information
dumpsys package xxx (package name)

Command pm

1) install an APK
PM install xxx.apk
such as: pm install /data/3dijoy_fane.apk
sometimes has not been installed during the installation, add the -r option on it.

2) View all current apk and paths
pm -lf

Other commonly used commands

aapt command can be used to view the apk package name, main activity, and many other information versions

apk system signature

1) find platform.pk8 platform.x509.pem and other signature file platform / build / target / product / security / directory
2) in / out / have signapk.jar next host / linux-x86 / framework / directory
3) Use command java -jar signapk.jar platform.x509.pem platform.pk8 MyDemo.apk (requiring a signature apk) MyDemo_signed.apk (generated name signed APK)

2, the stack-related

addr2line

Usage: addr2line -e xxx address can addr2line --help view
addr2line linux is commonly used in the stack trace debugging tools in android, the crash some libraries, you can use addr2line to find the problem, is very convenient. Provided that the library does not strip, so we debugging, go out obj directory to find the corresponding non-strip library.
example:

I/DEBUG   ( 1444): backtrace:
I/DEBUG   ( 1444):     #00  pc 00022048  /system/lib/libc.so (tgkill+12)
I/DEBUG   ( 1444):     #01  pc 00013099  /system/lib/libc.so (pthread_kill+48)
I/DEBUG   ( 1444):     #02  pc 000132ad  /system/lib/libc.so (raise+10)
I/DEBUG   ( 1444):     #03  pc 0003b9c0  /system/lib/libc.so (__aeabi_idiv0+8)
I/DEBUG   ( 1444):     #04  pc 000003cf  /system/lib/libfunc.so (function+6)

addr2line -e ./out/target/product/Hi3796MV100/obj/SHARED_LIBRARIES/libfunc_intermediates/LINKED/libfunc.so 000003cf

/home/wusc/Hi3796MV100-2015-2-3-CP058/anticopy/function.c:8
这样我们就知道错误是在function.c的第八行

core dump debugging with gdb

Usage:
1, in the terminal input: the ulimit -C Unlimited
2, if necessary, can be put u coredump disk,
echo "/ mnt / USB / E- core-%%% p-T"> / proc / SYS / Kernel / core_pattern
. 3, execute the executable file, and generates the dump Core
. 4, 777 Core modify the permissions the chmod
. 5, at the end pc performed gdb main.out core

Printing Stack

When APK or system problems, the system itself will generate the appropriate stack.
The ANR /data/anr/traces.txt will
crash as a program, is generated in the file / data / tombstone

Of course, we can also increase their development stack tracking code:

1, java code printing stack

Java code is relatively simple printing stack, the stack information acquisition and output. The usual approach is the use of exception printStackTrace () Method:

try {
 ...
} catch (RemoteException e) {
  e.printStackTrace();
  ...
}

Of course you can print only the stack does not exit, so it is more convenient operation of the dynamic analysis of the code. Java code is inserted into the stack of printing as follows:
Log.d (the TAG, Log.getStackTraceString (the Throwable new new ()));

Usually we can also combine the ps command to see who the corresponding process is clear to see the code calls the procedure.

2, C ++ code printing stack

C ++ also supports exception handling, exception handling library already contains acquisition backtrace interface, Android also use this interface to print stack information. In the Android C ++, a class has been integrated tool CallStack, in libutils.so in. Instructions:

#include <utils/CallStack.h>
...
CallStack stack;
stack.update();
stack.dump(); 

3, system-level debugging command

dumpsys

Usage: dumpsys service
list information of the service. Very strong, we can see a lot of information.
service can be viewed through the service list command system which service, general, dumpsys will be added to grep to filter out the fields you want, or a little too much information.

bugreport

Usage: bugreport> xxx.log
This command is very useful practical applications, can save a detailed dumpsys, dumpstate and logcat information after boot.

The cat command node information see

This is not to say, because each chip in accordance with their different modifications to the kernel, the node information is certainly not the same, but basically we all can view the status of the system and run through sys proc, the actual work in very useful.

top view and free cpu and memory conditions

Usage: top -t -d 1 -m 10 in every 1s, shows up to 10 threads.
-p pid Top
Top --help
usage of the cpu memory of view the process (thread).
free command lists the current memory usage.

Above these commands, you can use the command with the watch, so that can automatically query has been in regular intervals to
watch -n xxx (the number of seconds) yyyy (command)

Guess you like

Origin blog.csdn.net/myvest/article/details/91411708