Является ли файл library.so поврежденным, если копируется с использованием inputtream и outputtream - PullRequest
0 голосов
/ 23 сентября 2019

Я пытаюсь создать системное приложение, которое будет копировать файл library.so из ресурсов в папку / data / local / tmp / на устройстве Android и использовать LD_LIBRARY_PATH для загрузки и выполнения при необходимости.Но после копирования .so файла с использованием следующего метода результат выполнения не совпадает с тем, как выглядит .so файл поврежден.

Кто-нибудь знает, почему это происходит и как это можно исправить?

 private void copyFromAssets(String filename, String destinationPath) {

    Log.d(TAG, "copyFromAssets: " + filename);
    AssetManager assetManager = getResources().getAssets();

    InputStream in = null;
    OutputStream out = null;
    try {
        in = assetManager.open(filename);
        File file = new File(destinationPath);
        File outFile = new File(file, filename);
        if (!outFile.exists()) {
            outFile.createNewFile();
        }
        Log.d(TAG, "Output file: " + outFile.getPath());
        out = new FileOutputStream(outFile);
        copyFile(in, out);
        outFile.setExecutable(true);

    } catch (IOException e) {
        Log.e(TAG, "Failed to copy asset file: " + filename, e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // NOOP
            }
        }
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                // NOOP
            }
        }
    }
}


private void copyFile(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int read;
    while ((read = in.read(buffer)) != -1) {
        out.write(buffer, 0, read);
    }
}
...