歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 如何在Android源碼裡查找Java中native方法對應的C++實現

如何在Android源碼裡查找Java中native方法對應的C++實現

日期:2017/3/1 10:23:47   编辑:Linux編程

在Android源碼裡,有許多方法都是使用Jni機制調用底層的C++實現,比如大家都很熟悉的Binder.java裡,就有

public static final native int getCallingPid();

public static final native int getCallingUid();

public static final native long clearCallingIdentity();

等方法都是直接調用C++裡的實現。

通過下面命令可以很快找到對應的實現,

. build/envsetup

cgrep ./frameworks '"getCallingPid"'

這時會查找到如下結果:

./frameworks/base/core/jni/android_util_Binder.cpp:745: { "getCallingPid", "()I", (void*)android_os_Binder_getCallingPid },

這樣就可以知道對應的C++實現方法名字為android_os_Binder_getCallingPid, 在該文件中找這個方法的實現即可。

Copyright © Linux教程網 All Rights Reserved