【发布时间】:2020-04-27 13:00:40
【问题描述】:
我正在从以前创建的 Angular 应用程序创建移动应用程序。我使用了this 教程,该教程解释了如何使用cordova 从角度创建本机应用程序。我已经执行了以下步骤:
- 安装科尔多瓦
- 添加了环境变量
- 将 Cordova 添加到应用程序中
- 使用
cordova create mobile创建了一个cordova 应用程序,它在<myprojectpath>/mobile中创建了cordova 项目 - 创建了一个软链接
www重定向到应用程序的 dist 文件夹 - 添加 android 作为平台(使用
sudo权限,否则无法执行) - 创建的构建
- 使用
cordova requirements检查需求,看看是否缺少任何东西 - 在终端中运行
cordova run android(使用sudo权限,否则无法执行)
它给了我以下错误:
“路径”参数必须是字符串类型。接收到的类型对象
在错误之前提供以下信息
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=/home/<usr>/Android/Sdk (DEPRECATED)
No target specified and no devices found, deploying to emulator
No emulator specified, defaulting to Pixel_API_28
添加--verbose 给了我以下信息:
The "path" argument must be of type string. Received type object
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
at validateString (internal/validators.js:112:11)
at Object.dirname (path.js:1129:5)
at /var/www/html/employee_portal/mobile/platforms/android/cordova/lib/emulator.js:294:37
at _fulfilled (/var/www/html/employee_portal/mobile/node_modules/q/q.js:854:54)
at /var/www/html/employee_portal/mobile/node_modules/q/q.js:883:30
at Promise.promise.promiseDispatch (/var/www/html/employee_portal/mobile/node_modules/q/q.js:816:13)
at /var/www/html/employee_portal/mobile/node_modules/q/q.js:624:44
at runSingle (/var/www/html/employee_portal/mobile/node_modules/q/q.js:137:13)
at flush (/var/www/html/employee_portal/mobile/node_modules/q/q.js:125:13)
at processTicksAndRejections (internal/process/task_queues.js:75:11)
我检查了一些关于 stackoverflow 的问题,这些问题指向与 ionic 相关的类似问题,例如 undefined path error 和 path error after upgrade,但我无法使用这些解决方案解决它们。我不确定为什么会发生这种情况,因为当我运行 cordova build 时,它会创建没有任何问题的 apk。
我也尝试删除 node_modules 文件夹并在我的 mobile 文件夹中运行 npm install,但没有帮助。
我不确定为什么会导致此错误以及如何解决它
cordova requirements的结果:
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: installed android-29,android-28,android-27
Gradle: installed /opt/gradle/gradle-5.2.1/bin/gradle
平台版本:
Installed platforms:
android 8.1.0
Available platforms:
browser ^6.0.0
electron ^1.0.0
ios ^5.0.0
osx ^5.0.0
windows ^7.0.0
我的cordova项目的package.json:
{
"name": "helloworld",
"displayName": "HelloCordova",
"version": "1.0.0",
"description": "A sample Apache Cordova application that responds to the deviceready event.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"ecosystem:cordova"
],
"author": "Apache Cordova Team",
"license": "Apache-2.0",
"dependencies": {
"cordova-android": "^8.1.0"
},
"devDependencies": {
"cordova-plugin-whitelist": "^1.3.4"
},
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {}
},
"platforms": [
"android"
]
}
}
【问题讨论】: