- Home /
"system.componentmodel.win32exception" when trying to run stockfish binary file for android
I am creating a Chess Game in Unity. I want to build my game for Android. For AI I am using Stockfish Chess Engine and more particularly "Stockfish-9-arm64v8" file which is a binary file for Android. I have created a C# script which creates a process to run this binary file and communicate with it. When I try to Start my process the exception is raised ->
try{ mProcess.Start() } catch(Exception e){ Helper.PrintString(e.GetType().ToString()); // ----------------(1) Helper.PrintString(e.Message); // --------------(2) } /* (1) is printing : system.componentmodel.win32exception (2) is printing : ApplicationName = '/storage/emulated/0/Android/data/com.chessmania.chess/files/Stockfish-9-arm64v8', CommandLine = '', CurrentDirectory = '' */
Also my process info parameters are as follows:
ProcessStartInfo si = new ProcessStartInfo() { FileName = System.IO.Path.Combine(Application.persistentDataPath, "Stockfish-9-arm64v8"), UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true, RedirectStandardInput = true, RedirectStandardOutput = true };
Can anyone please help me with it. I have been trying to resolve this issue past few days but unable to. Does it have something to do with file permission?? I mean shall I include some arguments in my ProcessInfoParameters to forcefully run the binary file?? I really don't know if this is the problem or something else? Correct me from the start if I am wrong.
I just want to integrate Stockfish Chess Engine with with Unity Project and build it for Android Platform. If anyone has any ideas or suggestions or if anyone has dealt with similar problem before, please let me know how to solve this issue. I would be grateful. Thanks for bearing with me till here :)
Answer by Sergey78 · May 14, 2018 at 08:02 AM
Are you storing this file in assets (assets of android project)? Try to use this command "chmod 744 filepath" to grant execute permission to your file before using it.
*https://answers.unity.com/questions/16675/running-an-external-exe-file-from-unity.html*
If you have root on your device, you can run this command in adb shell without code modification.
@$$anonymous$$y78 I stored my assets in Strea$$anonymous$$gAssets folder so that the executable(which in this case is stockfish binary for android) goes correctly into the targeted platform.Unfortunately my device is unrooted. Shall I change the process info parameters in someway to grant the execute permission. I changed my code as follows: ProcessStartInfo si = new ProcessStartInfo() { FileName = "Stockfish-9-arm64v8", UseShellExecute = false, CreateNoWindow = true, **Arguments = "chmod 744 " + Application.persistentDataPath**, RedirectStandardError = true, RedirectStandardInput = true, RedirectStandardOutput = true };
However the error message now it is giving is: ApplicationName = 'Stockfish-9-arm64v8', CommandLine = 'chmod 744 /storage/emulated/0/Android/data/com.chessmania.chess/files' CurrentDirectory = ''
Can you tell me the correct way of modifying my code so that it works for Android?
Thanks :)
@suresh_gandhi You got it wrong. chmod is a ter$$anonymous$$al command. You should use it before loading your file. When chmod process is finished you can try to load your file. It should look like this:
using UnityEngine;
using System.Collections;
using System.Diagnostics;
public class RunBat : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
Process foo = new Process();
foo.StartInfo.FileName = "chmod";
foo.StartInfo.Arguments = "744 " + yourFilePath;
foo.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
foo.Start();
}
// Update is called once per frame
void Update () {
}
}
Also, remember that your Android device should support arm64v8. It won't work on emulator or on old device.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Playerprefs not saving 1 Answer
Flip over an object (smooth transition) 3 Answers
How to ask for permissions in Android for communicating with stockfish binary in Unity 0 Answers