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

后端 未结 6 2043
自闭症患者
自闭症患者 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:42

    String libraryPath = context.getFilesDir().getParentFile().getPath() + "/lib";
    

    For better compatibility, use the following function:

    @TargetApi(Build.VERSION_CODES.GINGERBREAD)
    public static String getLibraryDirectory(Context context) {
        int sdk_level = android.os.Build.VERSION.SDK_INT;
    
        if (sdk_level >= Build.VERSION_CODES.GINGERBREAD) {
            return context.getApplicationInfo().nativeLibraryDir;
        } 
        else if (sdk_level >= Build.VERSION_CODES.DONUT) {
            return context.getApplicationInfo().dataDir + "/lib";
        }
    
        return "/data/data/" + context.getPackageName() + "/lib";
    }
    

提交回复
热议问题