[英]Build gradle assemble apk using laravel function
I'm currently calling the main python file in larval function, and inside that main python file I'm calling another 2 files ( PowerShell and sub python file) the problem is when the Laravel function is triggered it only call the main python file, however when I call the main python file using terminal all the files are executed like below: I'm currently calling the main python file in larval function, and inside that main python file I'm calling another 2 files ( PowerShell and sub python file) the problem is when the Laravel function is triggered it only call the main python file,但是,当我使用终端调用主 python 文件时,所有文件的执行如下:
Laravel function: Laravel function:
public function initialize(Request $request)
{
$store_name = $request->get('store_name', 1);
if (empty($store_name)) {
return 'Missing store name';
} else {
$processes = File::get("/root/flask/android_api/processes.txt");
File::put('/root/flask/android_api/url.txt', $store_name );
$process = new Process(['python3.6', '/root/flask/android_api/buildAPK.py']);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
} else {
return 'Starting the processes to build';
}
}
}
and within the main python file I have:在主 python 文件中,我有:
try:
p = subprocess.Popen(["/usr/bin/pwsh",
"/root/flask/android_api/set_apk_builder.ps1", '-ExecutionPolicy',
'Unrestricted',
'./buildxml.ps1'],
stdout=sys.stdout)
p.communicate()
except:
file = open ("/root/flask/android_api/log.txt", "w")
file.write ("fail")
file.close()
import slack
// call(["python", "/root/flask/flask.py"])
os.system('python3.7 /root/flask/flask.py')
Edit:编辑:
now I changed the build to be direct from laravel function to generate the apk using this command:现在我将构建更改为直接从 laravel function 使用以下命令生成 apk:
public function initialize(Request $request)
{
$store_name = $request->get('store_name', 1);
if (empty($store_name)) {
return 'Missing store name';
} else {
return shell_exec('cd /var/www/html/androidProject && chmod +x gradlew && ./gradlew assembledemoDebug');
}
}
however, the command line returns the Gradle command build is starting but it doesn't create a folder and generate the apk但是,命令行返回 Gradle 命令构建正在启动,但它不会创建文件夹并生成 apk
the Current folder structure /var/www/html and inside html is the project folder and laravel project当前文件夹结构 /var/www/html 和内部 html 是项目文件夹和 laravel 项目
note: before I call Gradle build command inside Laravel function, I used to call python file and that python file is calling Gradle command but I had the same issue the apk is not created, but when I run the same python file from bash command it works fine note: before I call Gradle build command inside Laravel function, I used to call python file and that python file is calling Gradle command but I had the same issue the apk is not created, but when I run the same python file from bash command it工作正常
There are 2 ways you can accomplish this:有两种方法可以完成此操作:
The first is to include your commands into a.sh file that you should make it executable using this command:第一个是将您的命令包含到一个 .sh 文件中,您应该使用以下命令使其可执行:
chmod +x file.sh chmod +x 文件.sh
Then you should call that file from laravel using Symfony process so you can get details of the log process and errors:然后,您应该使用 Symfony 进程从 laravel 调用该文件,以便获取日志进程和错误的详细信息:
use Symfony\Component\Process\Process;使用 Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\ProcessFailedException;使用 Symfony\Component\Process\Exception\ProcessFailedException;
$process = new Process('sh /folder_name/file_name.sh');
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
Then include all commands in that file you wish to run.然后在您希望运行的文件中包含所有命令。
Second you can run those commands using其次,您可以使用运行这些命令
$output = shell_exec('ls -lart');
then echo "<pre>$output</pre>";
You'll need to move all your writable files into public directory in Laravel, because that's where everything should be editable.'=您需要将所有可写文件移动到 Laravel 的公共目录中,因为那是所有内容都应该可编辑的地方。'=
I actually suggest the first one as you don't need to change owner of some folders to www-data to give write permissions.我实际上建议第一个,因为您不需要将某些文件夹的所有者更改为 www-data 以授予写入权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.