oid源代码中创建的PathClassLoader实例的位置和时

oid源代码中创建的PathClassLoader实例的位置和时

本文介绍了在Android源代码中创建的PathClassLoader实例的位置和时间是什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我研究android源代码时,我注意到app中的通用类加载器是 PathClassLoader 的实例,并且此类中有两个构造函数。一个是:

When I was studying android source code, I noticed that the general class loader in app is an instance of PathClassLoader, and there is two constructors in this class. One is like:

 public PathClassLoader(String dexPath, ClassLoader parent) {
     super(dexPath, null, null, parent);
 }

另一个是:

  public PathClassLoader(String dexPath, String libraryPath,
          ClassLoader parent) {
      super(dexPath, null, libraryPath, parent);
  }

但我在源代码中找不到第二个构造函数的调用应用程序启动程序。那么libraryPath参数的价值来自哪里?众所周知, libraryPath 是指包含本机库的目录列表,用于初始化 nativeLibraryDirectories 的值,这是一个字段DexPathList对象。因此,如果第二个构造函数没有调用三个参数,那么如何初始化 nativeLibraryDirectories 的值?因此,应用程序如何找到其原生库?

But I cannot find the call of the second constructor in the source code during the procedure of app launching. So where does the value of libraryPath param come from? As it is known that libraryPath refers to the list of directories containing native libraries, and is used for initializing the value of nativeLibraryDirectories, which is a field of DexPathList object. So if there is no call of the second constructor with three params, how can the value of nativeLibraryDirectories be initialized? Therefore how can an app find its native libraries?

实际上,我想知道谁来决定nativeLibraryDirectories的价值?

希望有人可以指导我。非常感谢。

Hope some one can guide me in this. Thanks a lot.

推荐答案

您可以使用Android Studio搜索找到它。执行在路径中查找,为Android源目录指定Scope参数。作为在正则表达式后面找到粘贴的文本:

You can use Android Studio search to find it out. Perform "Find in Path", specifying the "Scope" parameter to directory of Android sources. As a text to find paste following regex expression:

new PathClassLoader\(\w+, \w+, \w+\)\;

这与具有三个参数的构造函数的调用相匹配。另外,不要忘记检查正则表达式复选框:

This matches a call of the constructor with three params. Also, do not forget to check "Regular expression" checkbox:

然后在预览标签中,您将能够看到结果:

Then in the preview tab you'll be able to see the results:

使用相同的技术,您可以找出谁正在调用 PathClassLoaderFactory #creinClassLoader()功能:

With the same technique you can find out who is calling PathClassLoaderFactory#createClassLoader() function:

ZygoneInit .java 您将能够找到以下代码:

In ZygoneInit.java you'll be able to locate following piece of code:



    /**
     * Creates a PathClassLoader for the system server. It also creates
     * a shared namespace associated with the classloader to let it access
     * platform-private native libraries.
     */
    private static PathClassLoader createSystemServerClassLoader(String systemServerClasspath,
                                                                 int targetSdkVersion) {
      String librarySearchPath = System.getProperty("java.library.path");

      return PathClassLoaderFactory.createClassLoader(systemServerClasspath,
                                                      librarySearchPath,
                                                      null /* libraryPermittedPath */,
                                                      ClassLoader.getSystemClassLoader(),
                                                      targetSdkVersion,
                                                      true /* isNamespaceShared */);
    }

现在,回到你的问题。

ZygoteInit#handleSystemServerProcess()调用 createSystemServerClassLoader(),最终会调用3 args构造函数 PathClassLoader

There is, ZygoteInit#handleSystemServerProcess() calls createSystemServerClassLoader(), which would eventually call 3 args constructor of PathClassLoader.

从上面的代码可以看出,它默认为系统属性java.library.path

As you can see from the code above, it defaults to system property "java.library.path".

这篇关于在Android源代码中创建的PathClassLoader实例的位置和时间是什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 07:58