PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 1, 2022

[FIXED] Build gradle assemble apk using laravel function

 March 01, 2022     android, gradle, laravel-5, linux, python     No comments   

Issue

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:

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:

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:

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

the Current folder structure /var/www/html and inside html is the project folder and laravel project

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


Solution

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:

chmod +x file.sh

Then you should call that file from laravel using Symfony process so you can get details of the log process and errors:

use Symfony\Component\Process\Process; use 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.'=

I actually suggest the first one as you don't need to change owner of some folders to www-data to give write permissions.



Answered By - Mohamed Gabr
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing