Код: Выделить всё
Cannot run program "/data/user/0/com.example.chess/files/stockfish-arm64-v8a": error=13, Permission denied
Код: Выделить всё
String abi = getAbi();
String stockfishName = "stockfish-" + abi;
File stockfishFile = new File(context.getFilesDir(), stockfishName);
Log.d(TAG, "Stockfish file path: " + stockfishFile.getAbsolutePath());
if (!stockfishFile.exists()) {
Log.d(TAG, "Stockfish file does not exist. Copying from assets...");
copyStockfishFromAssets(stockfishName);
}
logFileDetails(stockfishFile);
Log.d(TAG, "Starting Stockfish process...");
ProcessBuilder pb = new ProcessBuilder(stockfishFile.getAbsolutePath());
pb.redirectErrorStream(true);
try {
process = pb.start();
Log.d(TAG, "Stockfish process started successfully");
Код: Выделить всё
private void copyStockfishFromAssets(String stockfishName) throws IOException {
Log.d(TAG, "Copying Stockfish from assets: " + stockfishName);
InputStream inputStream = context.getAssets().open(stockfishName);
File outputFile = new File(context.getFilesDir(), stockfishName);
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
}
Log.d(TAG, "Stockfish copied successfully. Setting executable permission...");
if (!outputFile.setExecutable(true, true)) {
Log.e(TAG, "Failed to set executable permission programmatically");
}
}
ПРИМЕЧАНИЕ. Я новичок в Android, поэтому рабочий код или какое-то руководство к нему будет очень полезно
Подробнее здесь: https://stackoverflow.com/questions/790 ... rm64-v8a-e