Where and when is the instance of PathClassLoader created in android source code?

一笑奈何 提交于 2019-12-05 20:41:22

So where does the value of libraryPath param come from?

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:

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

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 */);
    }

Now, back to your questions.

So if there is no call of the second constructor with three params...

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

Actually, I am wondering who determines the value of nativeLibraryDirectories?

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!