SO Android 库的运行时目录在哪里?
Where is the runtime directory for SO Android libs?
我有一个 Android 应用程序,它使用外部 .so
库来工作 (OpenALPR)。
此 .so
库还需要一个外部配置文件才能正常工作。当我加载我的库并对其进行初始化时,我需要在本机函数中指定 conf 文件到库的路径。
private native void initialize(String country, String configFile, String runtimeDir);
这是我的项目结构:
我应该给哪条路? 我找不到将我的文件放在哪里以便我的图书馆可以看到它们
诀窍是手动将资产的内容移动到实际的 /data/data/com.example.app/
文件夹,这是存储库的地方。
这是实现这一目标的代码片段 (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);
}
}
我有一个 Android 应用程序,它使用外部 .so
库来工作 (OpenALPR)。
此 .so
库还需要一个外部配置文件才能正常工作。当我加载我的库并对其进行初始化时,我需要在本机函数中指定 conf 文件到库的路径。
private native void initialize(String country, String configFile, String runtimeDir);
这是我的项目结构:
我应该给哪条路? 我找不到将我的文件放在哪里以便我的图书馆可以看到它们
诀窍是手动将资产的内容移动到实际的 /data/data/com.example.app/
文件夹,这是存储库的地方。
这是实现这一目标的代码片段 (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);
}
}