official-pikafish / Pikafish

UCI xiangqi engine
http://pikafish.org
GNU General Public License v3.0
867 stars 162 forks source link

Android target SDK > 28 can no longer execute binaries in the data directory. #49

Closed myisduy closed 9 months ago

myisduy commented 1 year ago

Describe the issue

From android 10 version, we cannot execute binary file without root permission. If they set targetSDK = 28, they cannot be released on the play store.

Expected behavior

Any method that integrates the engine

Steps to reproduce

public class Engine { public Engine(File engineFile) { String command = engineFile.getAbsolutePath(); try { Process process = Runtime.getRuntime().exec(command);

        InputStream inputStream = process.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ((line = reader.readLine()) != null) {

            Log.i("enginechess", line);
        }

        int exitCode = process.waitFor();
        Log.i("enginechess", "Exit code: " + exitCode);
    } catch (IOException | InterruptedException e) {
        e.printStackTrace();
    }

}

Anything else?

No response

Operating system

Android

Pikafish version

Pikafish 2023-03-05

PikaCat-OuO commented 12 months ago

Ask about this issue in the upstream repo(https://github.com/official-stockfish/Stockfish) and see if there are any actions that need to be done. The NDK version Pikafish uses is fully synced with Stockfish.

Liberations commented 10 months ago

1.change name to libpikafish.so . move to project app/src/main/jniLibs/arm64-v8a 2.pikafish.nnue to assets/pikafish.nnue

        String apkFilePath = getPackageCodePath();
        // 推断lib目录路径
        LIB_PATH = apkFilePath.substring(0, apkFilePath.lastIndexOf("/")) + "/lib/arm64";
        File cacheDir = getCacheDir();
        String outputFilePath = cacheDir.getAbsolutePath() + File.separator + "pikafish.nnue";
        ENGIN_PATH = outputFilePath;
        Log.d(TAG, "lib目录路径: " + LIB_PATH);
        Log.d(TAG, "引擎路径: " + ENGIN_PATH);
        // 解压NNUE;
        AssetUtils.extractAssetFile(this, "pikafish.nnue");

3. Runtime.getRuntime().exec(LIB_PATH + "/libpikafish.so")

PikaCat-OuO commented 9 months ago

I'll mark this as resolved now.