SO Android 库的运行时目录在哪里?

编程入门 行业动态 更新时间:2024-10-09 03:32:36
本文介绍了SO Android 库的运行时目录在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 Android 应用,它使用外部 .so 库来工作 (OpenALPR).

I have an Android app that uses an external .so library to work (OpenALPR).

这个 .so 库还需要一个外部 conf 文件才能正常工作.当我加载我的库并初始化它时,我需要在本机函数中指定 conf 文件到库的路径.

This .so library also needs an external conf file to work properly. When I load my library and initialize it, I need to specify the path of the conf file to the library, in a native function.

private native void initialize(String country, String configFile, String runtimeDir);

这是我的项目结构:

我应该给哪条路?我不知道把我的文件放在哪里,以便我的图书馆可以看到它们

推荐答案

诀窍是手动将 Assets 的内容移动到实际的 /data/data/com.example.app/ 文件夹中,这是存储库的地方.

The trick was to move manually the content of Assets to the actual /data/data/com.example.app/ folder, which is where the libs are stored.

这是实现这一目标的片段(来自官方 android 存储库)

Here's a snippet that achieves that (from the official android repo)

/** * Copies the assets folder. * * @param assetManager The assets manager. * @param fromAssetPath The from assets path. * @param toPath The to assets path. * * @return A boolean indicating if the process went as expected. */ public static boolean copyAssetFolder(AssetManager assetManager, String fromAssetPath, String toPath) { try { String[] files = assetManager.list(fromAssetPath); new File(toPath).mkdirs(); boolean res = true; for (String file : files) if (file.contains(".")) { res &= copyAsset(assetManager, fromAssetPath + "/" + file, toPath + "/" + file); } else { res &= copyAssetFolder(assetManager, fromAssetPath + "/" + file, toPath + "/" + file); } return res; } catch (Exception e) { e.printStackTrace(); return false; } } /** * Copies an asset to the application folder. * * @param assetManager The asset manager. * @param fromAssetPath The from assets path. * @param toPath The to assests path. * * @return A boolean indicating if the process went as expected. */ private static boolean copyAsset(AssetManager assetManager, String fromAssetPath, String toPath) { InputStream in = null; OutputStream out = null; try { in = assetManager.open(fromAssetPath); new File(toPath).createNewFile(); out = new FileOutputStream(toPath); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; return true; } catch (Exception e) { e.printStackTrace(); return false; } } /** * Copies a file. * * @param in The input stream. * @param out The output stream. * * @throws IOException */ private static void copyFile(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } }

更多推荐

SO Android 库的运行时目录在哪里?

本文发布于:2023-11-12 14:37:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581763.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:目录   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!