Android source framework modify rebuild but become

2019-05-26 09:29发布

问题:

i modify /framework/base/services/core/java/com/android/server/am/ActivityManagerService.java some logcat output string.

and i try to use different ways to rebuild it:

make -jN from top folder or

mmm /framework/base -jN or

mmm /framework/base/services -jN

and then i get a new output file in /out/target/product/generic_x86/system/framework/x86/services.odex

and then i update system.img by make snod

then i try to restart emulator, or adb remount adb sync, or kill system_server process

but sadly, no matter what kinds of methods i use, the emulator always output the original string.(so angry)

i even extract the new output system.img to get the new services.odex file, and use oat2dex.jar to decompile it to java code, and i indeed see the string has changed in it.

so why when i run the emulator, it won't become effective...

回答1:

The system image file used by the emulator is system-qemu.img. For some reason that file isn't made by make snod, which only makes system.img. I think what is needed is an additional target so you could say make qsnod or something, but there doesn't seem to be one. I don't know how anyone can work like this.

I don't understand the Makefile structure well enough at this point to figure out how to add a qsnod target, but here's a way to hand-roll system-qemu.img.

Notice that the very last step that make -nN reports is:

[100% 255/255] Create system-qemu.img

To find out what command it ran there, you can say make showcommands -jN. I did this, and found it was the following, on my Macbook Pro:

[100% 255/255] /bin/bash -c "(export SGDISK=out/host/darwin-x86/bin/sgdisk; device/generic/goldfish/tools/mk_qemu_image.sh out/target/product/generic_x86_64/system.img)"

So that's the command for making system-qemu.img from input system.img (which is what make snod makes).

So, my recipe for rebuilding system.img on my machine, after changing a .java file under framework/base, is:

mmm frameworks/base -jN
make snod -jN
SGDISK=out/host/darwin-x86/bin/sgdisk device/generic/goldfish/tools/mk_qemu_image.sh out/target/product/generic_x86_64/system.img

Then when I restart the emulator, I see that my change has taken effect.