How to get the path to the lib folder for an installed package

后端 未结 6 2075
自闭症患者
自闭症患者 2020-12-14 03:40

Shared libraries .so files are placed in lib/armeabi in an apk file.

I have read after installation the libs gets extracted to /data/data/application_package/lib

6条回答
  •  [愿得一人]
    2020-12-14 04:17

    Maybe a device support different CPU_ABIs, so it's better to get nativeRootLibraryDir which contain all sub lib directories:

    public static String getNativeLibraryDirectory(Context context) {
        int sdk_level = android.os.Build.VERSION.SDK_INT;
    
        if (sdk_level >= Build.VERSION_CODES.GINGERBREAD) {
            try {
                String secondary = (String) ApplicationInfo.class.getField("nativeLibraryRootDir").get(context.getApplicationInfo());
                return secondary;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
        else if (sdk_level >= Build.VERSION_CODES.DONUT) {
            return context.getApplicationInfo().dataDir + "/lib";
        }
    
        return "/data/data/" + context.getPackageName() + "/lib";
    }
    

提交回复
热议问题