因此,我正在尝试将ionic和Laravel结合在一起,目标是我可以根据iframe标记中显示的ionic / www 文件夹生成一个APK,而我的项目结构是像这样:
- app
- artisan
- config
- database
- public
- css
- js
- mobileapps
- helloworld
- www
- index.html (this is ionic generated /www folder that i show in my example site)
- resourece
- vendor
- etc...
我已经使用 exec(), shell_exec()和反引号函数来生成运行 ionic Cordova构建android >。我实际上尝试在shell中手动运行此命令,并且运行良好,但是在输入exec()命令后出现错误,我还将项目权限更改为 777 并将所有者设置为< strong> www数据仍然没有运气。
这是我的DemoController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class DemoController extends Controller {
public function index() {
return view('demo.index');
}
public function getAPK() {
// download the apk
ini_set('max_execution_time', 180);
chdir('mobileapps/helloworld');
exec('ionic cordova build android 2>&1', $output);
return $output;
// i wanted to return below code in order to make it downloadable if above **exec()** is working
// return response()->download(public_path('mobileapps/helloworld/platforms/android/app/build/outputs/apk/debug/app-debug.apk'));
}
}
这是我的路线web.php
<?php
Route::get('/', function () {
return view('welcome');
});
Route::get('/demo', 'DemoController@index');
Route::post('/getapk', 'DemoController@getAPK');
?>
上面的$ output看起来像这样:
> cordova platform add android --save path.js:39 throw new
ERR_INVALID_ARG_TYPE('path', 'string', path); ^ TypeError
[ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string.
Received type undefined at assertPath (path.js:39:11) at Object.join
(path.js:1152:7) at Object.
(/usr/lib/node_modules/cordova/node_modules/cordova-
lib/src/cordova/util.js:36:31) at Module._compile
(internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js
(internal/modules/cjs/loader.js:700:10) at Module.load
(internal/modules/cjs/loader.js:599:32) at tryModuleLoad
(internal/modules/cjs/loader.js:538:12) at Function.Module._load
(internal/modules/cjs/loader.js:530:3) at Module.require
(internal/modules/cjs/loader.js:637:17) at require
(internal/modules/cjs/helpers.js:22:18) [ERROR] An error occurred while running subprocess cordova. cordova platform add android --save exited with exit code 1. Re-running this command with the --verbose flag may provide more information.
我想要的是 exec(), shell_exec()和反引号,以运行 ionic Cordova构建android >没有上述错误,以便我可以获取APK文件。
对不起,如果我的英语不好,我会尽力解释,希望您理解。感谢您的帮助。