How to detect which native shared libraries are loaded by Android application

前端 未结 2 1603
终归单人心
终归单人心 2020-12-16 02:21

My application uses native shared library (.so), I am loading it by calling System.loadLibrary(\"xxx\"). It loads fine and I can call the native methods.

相关标签:
2条回答
  • 2020-12-16 02:40

    Use this code to list the shared native libraries that can be loaded from your app:

    final File nativeLibraryDir = new File(getApplicationInfo().nativeLibraryDir);
    final String[] primaryNativeLibraries = nativeLibraryDir.list();
    
    0 讨论(0)
  • 2020-12-16 02:48

    The solution is simple, many thanks to @ praetorian-droid

      try {
            Set<String> libs = new HashSet<String>();
            String mapsFile = "/proc/" + android.os.Process.myPid() + "/maps";
            BufferedReader reader = new BufferedReader(new FileReader(mapsFile));
            String line;
            while ((line = reader.readLine()) != null) {
                if (line.endsWith(".so")) {
                    int n = line.lastIndexOf(" ");
                    libs.add(line.substring(n + 1));
                }
            }
            Log.d("Ldd", libs.size() + " libraries:");
            for (String lib : libs) {
                Log.d("Ldd", lib);
            }
        } catch (FileNotFoundException e) {
            // Do some error handling...
        } catch (IOException e) {
            // Do some error handling...
        }
    
    0 讨论(0)
提交回复
热议问题