2
votes

I'm developing a php function for execute a command that's build gradle project Android.

But to be clear I want to create a small system can modify a android project source and generate the APK project by build the gradle.

I do a lot of search about it and I found some close question but not with this command.

This is my function. It's really simple, I have already installed gradle tools in my server, and the command runs successfully in my terminal

function generator(){
    exec('cd /home/my/AndroidStudioProjects/BetaProject/;./gradlew assembleDebug 2>&1',$out,$err);
    var_dump($out); 
    var_dump($err); 
}

But, when I execute it with php it's gives me this :

string(955) "Exception in thread "main" java.lang.RuntimeException: java.io.FileNotFoundException: /usr/sbin/.gradle/wrapper/dists/gradle-2.4-all/3i2gobhdl0fm2tosnn15g540i0/gradle-2.4-all.zip.lck (No such file or directory) at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:78) at org.gradle.wrapper.Install.createDist(Install.java:47) at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129) at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48) Caused by: java.io.FileNotFoundException: /usr/sbin/.gradle/wrapper/dists/gradle-2.4-all/3i2gobhdl0fm2tosnn15g540i0/gradle-2.4-all.zip.lck (No such file or directory) at java.io.RandomAccessFile.open0(Native Method) at java.io.RandomAccessFile.open(RandomAccessFile.java:316) at java.io.RandomAccessFile.(RandomAccessFile.java:243) at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:49) ... 3 more "

If there's any solution or some advice, I will be so glad.

Thanks

2
Check your environmental path by php_info().Terminal and php have different value. - Mari Murotani
thanks , but i had check my path by ls command and yes my path is inside my php project but that's not problem because i have use cmd for going to gradle directory ! and i tested that in terminal everything is ok but with exec gives me that error. - MrMehdi
Did you ever figure this out? - Cody

2 Answers

1
votes

try this:

function generator(){

        exec('sh /home/my/AndroidStudioProjects/BetaProject/gradlew assembleDebug 2>&1',$out,$err);
        var_dump($out); 
        var_dump($err); 
}
0
votes

I was facing the same issue, and I fixed it just by giving apache permission to execute these scripts by changing the owner of the directory where these files reside

It's going to be something like this:

sudo chown -R www-data your-directory/ 

I hope this is going to work for you.