I have built a website that includes functionality for users to build .apk files. The process involves several steps:
- Get a copy from the main default Android app for the specific user.
- Allow users to copy their own assets.
- Build the app.
When building the app, my code executes a .bat file using the following command:
./gradlew build assembleDebug assembleDebugUnitTest assembleDebugAndroidTest
Here is the relevant part of my code for executing the function:
const util = require("util");
const exec = util.promisify(require("child_process").exec);
await exec(`${andpath}\assembleDebug.bat`, (error, stdout, stderr) => {
process.chdir(originalDirectory);
if (error) {
console.log("error" + error);
res.status(500).json({ success: false, error: "APK build failed" });
} else {
console.log("APK build successful");
res.status(200).json({ success: true });
}
});
This setup works correctly on my local machine. However, when I deploy it on the server, I encounter the following error:
errorError: Command failed: ./assembleDebug.bat
FAILURE: Build failed with an exception.
* What went wrong:
java.io.IOException: Permission denied
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Additional Information:
- The server is running on Linux.
- I am not using Android Studio IDE.
- I have verified that the .bat file exists and is in the correct directory.
- I have checked file permissions and they appear to be set correctly.
- When I manually run the .bat file on the server terminal, it builds the APK successfully.
- I have executed the command chmod -R +x ./androidproject.
Questions:
What could be causing this Permission denied error when running the Gradle command via the Node.js script on the server?
How can I resolve this issue to successfully build the .apk file on the server through the script?
Any help would be greatly appreciated!
What I Have Tried:
- Checking and adjusting file permissions.
- Running the command manually on the server, which builds the APK successfully.
- Executing chmod -R +x ./androidproject.