系统版本为4.4.4
手机为n4
初始化环境
[email protected]:~/Desktop/android$ export CLASSPATH=/home/haidragon/Desktop/jdk1.6.0_45_bin/jdk1.6.0_45/lib
[email protected]:~/Desktop/android$ export JAVA_HOME=/home/haidragon/Desktop/jdk1.6.0_45_bin/jdk1.6.0_45
[email protected]:~/Desktop/android$ export PATH=$PATH:/home/haidragon/Desktop/jdk1.6.0_45_bin/jdk1.6.0_45/bin
[email protected]:~/Desktop/android$
source build/envsetup.sh
lunch
编译然后建立连接https://blog.51cto.com/haidragon/2415339
make (/home/haidragon/Desktop/make-3.82/make -j16)
make idegen
source development/tools/idegen/idegen.sh
找到system_process的java层入口函数,如图所示。
路径为:‘/home/haidragon/Desktop/android/frameworks/base/services/java/com/android/server/SystemServer.java‘
.............................................
private static native void nativeInit();
public static void main(String[] args) {
/*
* In case the runtime switched since last boot (such as when
* the old runtime was removed in an OTA), set the system
* property so that it is in sync. We can‘t do this in
* libnativehelper‘s JniInvocation::Init code where we already
* had to fallback to a different runtime because it is
* running as root and we need to be the system user to set
* the property. http://b/11463182
*/
//--------------------------haidragon--------------------------------//
java.io.File f = new java.io.File("/system/debug");
if(f.exists()){
android.ddm.DdmHandleAppName.setAppName("system_process",
UserHandle.myUserId());
android.os.Debug.waitForDebugger();
}
//--------------------------haidragon--------------------------------//
SystemProperties.set("persist.sys.dalvik.vm.lib",
VMRuntime.getRuntime().vmLibrary());
.............................................
这么写的原因是我们可以控制什么时候打开调试,当我们在system创建debug文件时就是打开调试了。
刷手机。
开机adb去system目录创建debug文件,重启手机
[email protected]:/system # mkdir debug
mkdir failed for debug, Read-only file system
255|[email protected]:/system # mount -o rw,remount /system
[email protected]:/system # mkdir debug
[email protected]:/system # ls
手机就会一直等待调试器。我们可以用monitor看看(先把as关掉不然俩个冲突了),用android studio里面自带的。初始化环境变量(最好用自带jdk不然无法启动)
[email protected]:~$ cd /home/haidragon/Android/Sdk
[email protected]:~/Android/Sdk$ ls
build-tools emulator fonts lldb ndk-bundle platforms sources
cmake extras licenses ndk patcher platform-tools tools
[email protected]:~/Android/Sdk$ cd tools/
[email protected]:~/Android/Sdk/tools$ ls
android emulator lib monitor package.xml source.properties
bin emulator-check mksdcard NOTICE.txt proguard support
[email protected]:~/Android/Sdk/tools$ ./monitor
ERROR: JAVA_HOME is not set and no ‘java‘ command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
lib/monitor- ERROR: JAVA_HOME is not set and no ‘java‘ command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation./monitor
./monitor: line 47: /home/haidragon/Android/Sdk/tools/lib/monitor-: No such file or directory
[email protected]:~/Android/Sdk/tools$ export CLASSPATH=‘/home/haidragon/Desktop/android-studio/jre/lib‘
[email protected]:~/Android/Sdk/tools$ export JAVA_HOME=‘/home/haidragon/Desktop/android-studio/jre‘
[email protected]:~/Android/Sdk/tools$ export PATH=$PATH:‘/home/haidragon/Desktop/android-studio/jre/jre/bin‘
[email protected]:~/Android/Sdk/tools$ ./monitor
可能还是无法启动要修改monitor源码。
.........................
oldwd=`pwd`
progdir=`dirname "${prog}"`
cd "${progdir}"
vmarch=`bin/archquery`
app=lib/monitor-${vmarch}/monitor
if [[ "Darwin" == `uname` ]]; then
app=${app}.app/Contents/MacOS/monitor
fi
if [[ ${vmarch} == "" ]]; then
echo "haidragon"
app=lib/monitor-x86_64/monitor
fi
echo ${vmarch}
echo $app
exec $app
.........................
打开是这样的,说明没问题,然后开户as附加调试。(关闭monitor)
sh ‘/home/haidragon/Desktop/android-studio/bin/studio.sh‘ &
然后附加调试。