我需要获取在 android 中随应用程序安装的库的路径。以下代码在 android Lolipop 中运行良好。但在牛轧糖中,它返回以下路径:“/data/user/0/com.package_name”虽然so文件存在的实际路径是:“/data/app/com.package_name-1/lib/arm64/lib_name.so ”。Lolipop 提供此路径:“/data/data/com.package_name”
static File getLibDirectory(Context context)
{
File dataDir = new File(context.getFilesDir().getParent()); //returns "/data/user/0/com.package_name"
Log.d(TAG, "dataDir: "+dataDir.getAbsolutePath() + " Existance: "+ dataDir.exists()); //exists
boolean isExsist = false;
if(new File(dataDir.getAbsolutePath(), "lib").exists())
isExsist=true;
Log.d(TAG, "libDir: "+new File(dataDir.getAbsolutePath(), "lib").getAbsolutePath() + " Existance: "+ isExsist); //dose not exists
return new File(dataDir.getAbsolutePath(), "lib");
}