Android 13+, 使用 userdebug 版本时,Android studio 中 attach to process 无法显示系统进程,导致提示不方便
修改文件:
alps/frameworks/base/core/java/com/android/internal/os/Zygote.java
static void applyDebuggerSystemProperty(ZygoteArguments args) {
// 此处限制只有ro.debuggable=1才允许
if (RoSystemProperties.DEBUGGABLE) {
args.mRuntimeFlags |= Zygote.DEBUG_ENABLE_JDWP;
}
}
部分系统比较新的话,此部分代码会被 google 修改为:
/**
* This will enable jdwp by default for all apps. It is OK to cache this property
* because we expect to reboot the system whenever this property changes
*/
private static final boolean ENABLE_JDWP = SystemProperties.get(
"persist.debug.dalvik.vm.jdwp.enabled").equals("1");
/**
* Applies debugger system properties to the zygote arguments.
*
* For eng builds all apps are debuggable. On userdebug and user builds
* if persist.debuggable.dalvik.vm.jdwp.enabled is 1 all apps are
* debuggable. Otherwise, the debugger state is specified via the
* "--enable-jdwp" flag in the spawn request.
*
* @param args non-null; zygote spawner args
*/
static void applyDebuggerSystemProperty(ZygoteArguments args) {
if (Build.IS_ENG || ENABLE_JDWP) {
args.mRuntimeFlags |= Zygote.DEBUG_ENABLE_JDWP;
}
}
可以手动还原,或者使用 prop 打开。