'How to ask for permissions in Android for communicating with stockfish binary in Unity

I am trying to load stockfish android binary for the android App.

 string filepath = Application.persistentDataPath + "/" + "stockfish.android.armv7.so";
        UnityEngine.Debug.Log(filepath);
        if (!File.Exists(filepath))
        {
            WWW executable = new WWW("jar:file://" + Application.dataPath + "!/assets/" + "stockfish.android.armv7.so");
            while (!executable.isDone)
            {
            }
            File.WriteAllBytes(filepath, executable.bytes);

            //change permissions via plugin

        }
        //code to get permissions to communicate with .so file

Stock fish location

Assets/Plugins/Android/stockfish-10-armv7.so

stockfish location in Android build

/data/com.DefaultCompany.NewUnityProject/files/stockfish.android.armv7.so```




adb logcat log

02-13 10:41:17.798: E/Unity(15538): Win32Exception: ApplicationName='/storage/emulated/0/Android/data/com.DefaultCompany.NewUnityProject/files/stockfish.android.armv7.so', CommandLine='', CurrentDirectory='', Native error= mono-io-layer-error (0)
02-13 10:41:17.798: E/Unity(15538):   at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 

 

Any ideas for handling such a case will be helpful.

I think my logic for Getting permission is broken. I have no idea how I can do it. Can this be done from scratch?

According to the post https://chess.stackexchange.com/questions/17685/how-to-send-uci-messages-from-c-app-to-stockfish-on-android

user grants permission using

string[] cmd = { "chmod", "744", Path.Combine(strToFolder, fileName) };
Java.Lang.Runtime.GetRuntime().Exec(cmd);

Java.Lang.Runtime part is the native java code. I am not sure how to achieve same thing in Unity



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source