Reputation: 1
I'm working on an Android app that needs to compile C++ code using the NDK and Clang(linux). In Android 11, I'm unable to execute Clang directly from internal storage due to storage and execution restrictions. Even though I have the NDK and Clang binaries placed in internal storage, when I try to execute them, I get permission errors.
I am currently trying to use ProcessBuilder to execute Clang like this:
ProcessBuilder processBuilder = new ProcessBuilder("/data/data/<my-app>/files/clang", "<source-file>.cpp", "-o", "<output>");
processBuilder.directory(new File("/data/data/<my-app>/files/"));
processBuilder.start();
However, I keep running into permission issues.
The error everytime shows like:
/system/bin/sh: ./clang++: can't execute: Permission denied
I would like to know:
How can I create a custom environment using Java within my app to execute Clang and compile C++ files?
Is there a way to bypass the restrictions of executing binaries in internal storage on Android 11?
Would using a chroot or similar environment inside my app help resolve this, and how can I set it up without requiring root access?
Are there any Android APIs or workarounds for invoking Clang or other native binaries securely in the app's private directory (/data/data//files/)?
Any suggestions or alternative approaches to achieve this in Android 11+?
Upvotes: 0
Views: 54