【发布时间】:2018-11-21 23:38:57
【问题描述】:
我已经完成了我的国际象棋 UI 应用程序,现在想加载一个国际象棋引擎来测试我的 UI 是否真的与 UCI 兼容。国际象棋引擎位于 Android 设备的下载文件夹中('/storage/emulated/0/Download')。这是运行的代码:
try {
File f = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
String path = f.getAbsolutePath();
String stockfishPath = path + "/Stockfish-9-armv64v8";
engineProcess = Runtime.getRuntime().exec(stockfishPath);
processReader = new BufferedReader(new InputStreamReader(
engineProcess.getInputStream()));
String sCurrentLine;
ArrayList<String> output = new ArrayList<>();
while ((sCurrentLine = processReader.readLine()) != null) {
output.add(sCurrentLine);
}
processWriter = new OutputStreamWriter(
engineProcess.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
}
当我运行它时,它在 exec() 方法上失败,因为它声称它找不到该文件,即使该文件存在于 Android 设备上。我尝试在 exec() 方法上运行“ls”命令,但“emulated”中的文件夹是空的。造成这种情况的明显原因可能是因为我没有查看/访问这些文件的权限,但我需要知道如何做到这一点(尽管在清单文件中添加了 READ_EXTERNAL_STORAGE 和 WRITE_EXTERNAL_STORAGE)。
是否有可能将引擎嵌入项目中的某个位置(在资源中?)并以某种方式将 adb-shell 嵌入其中?
【问题讨论】: