如何在 Ionic/Capacitor 中设置 Android Studio 的正确路径?
How do I set the proper path to Android Studio in Ionic/Capacitor?
我正在 Ionic/React 入门,在我的 Linux 铸币盒上。
Building an Ionic application using React
第一步进展顺利,但是当我进入将您的应用程序部署到 iOS 和 Android 第 5 步时,出现错误。
说明:
Open your project in Android Studio using the following command:
npx cap open android
首先我遇到路径错误:
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn /usr/local/android-studio/bin/studio.sh
ENOENT
这看起来很简单。那不是 android studio 在我的机器上的安装位置。
我用谷歌搜索了一下,然后在 node_modules 中进行了一些搜索,发现了 "androidStudioPath" 设置。我尝试将它添加到我项目的 capacitor.config.json 文件中,但没有任何区别。所以我仔细看了看代码,然后把它添加到一个 "linux" 对象中:
{
"appId": "us.jdege.mytestapp",
"appName": "mytestapp",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "build",
"linux": {
"androidStudioPath": "/var/.../studio.sh"
}
}
据我所知,这是正确的设置,我正在设置正确的路径。但它被忽略了。
jdege@linux-2016 ~/react-projects/mytestapp $ npx cap open android
[info] Opening Android project at /home/jdege/react-projects/mytestapp/android
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn /usr/local/android-studio/bin/studio.sh ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
如何在 Ionic/Capacitor 中设置 Android Studio 的正确路径?
使用来源,卢克!
正确的设置是"linuxAndroidStudioPath"。
在./node_modules/@capacitor/cli/dist/android/open.js中,你会发现:
common_1.logError('Unable to launch Android Studio. You must configure "linuxAndroidStudioPath" ' +
'in your capacitor.config.json to point to the location of studio.sh, using JavaScript-escaped paths:\n' +
'Example:\n' +
'{\n' +
' "linuxAndroidStudioPath": "/usr/local/android-studio/bin/studio.sh"\n' +
'}');
所以在 ./capacitor.config.json 这不起作用:
{
...
"androidStudioPath": "/var/.../studio.sh"
}
这行不通:
{
...
"linux": {
"androidStudioPath": "/var/.../studio.sh"
}
}
这样做:
{
...
"linuxAndroidStudioPath": "/var/.../studio.sh"
}
我使用 JetBrains Toolbox 在 macOS
上管理我的 Android Studio
要使用 npx cap open android
我必须导出 Android Studio 路径如下:
export CAPACITOR_ANDROID_STUDIO_PATH="/Users/myuser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.7199119/Android Studio.app"
我正在 Ionic/React 入门,在我的 Linux 铸币盒上。
Building an Ionic application using React
第一步进展顺利,但是当我进入将您的应用程序部署到 iOS 和 Android 第 5 步时,出现错误。
说明:
Open your project in Android Studio using the following command:
npx cap open android
首先我遇到路径错误:
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn /usr/local/android-studio/bin/studio.sh
ENOENT
这看起来很简单。那不是 android studio 在我的机器上的安装位置。
我用谷歌搜索了一下,然后在 node_modules 中进行了一些搜索,发现了 "androidStudioPath" 设置。我尝试将它添加到我项目的 capacitor.config.json 文件中,但没有任何区别。所以我仔细看了看代码,然后把它添加到一个 "linux" 对象中:
{
"appId": "us.jdege.mytestapp",
"appName": "mytestapp",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "build",
"linux": {
"androidStudioPath": "/var/.../studio.sh"
}
}
据我所知,这是正确的设置,我正在设置正确的路径。但它被忽略了。
jdege@linux-2016 ~/react-projects/mytestapp $ npx cap open android
[info] Opening Android project at /home/jdege/react-projects/mytestapp/android
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn /usr/local/android-studio/bin/studio.sh ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
如何在 Ionic/Capacitor 中设置 Android Studio 的正确路径?
使用来源,卢克!
正确的设置是"linuxAndroidStudioPath"。
在./node_modules/@capacitor/cli/dist/android/open.js中,你会发现:
common_1.logError('Unable to launch Android Studio. You must configure "linuxAndroidStudioPath" ' +
'in your capacitor.config.json to point to the location of studio.sh, using JavaScript-escaped paths:\n' +
'Example:\n' +
'{\n' +
' "linuxAndroidStudioPath": "/usr/local/android-studio/bin/studio.sh"\n' +
'}');
所以在 ./capacitor.config.json 这不起作用:
{
...
"androidStudioPath": "/var/.../studio.sh"
}
这行不通:
{
...
"linux": {
"androidStudioPath": "/var/.../studio.sh"
}
}
这样做:
{
...
"linuxAndroidStudioPath": "/var/.../studio.sh"
}
我使用 JetBrains Toolbox 在 macOS
上管理我的 Android Studio要使用 npx cap open android
我必须导出 Android Studio 路径如下:
export CAPACITOR_ANDROID_STUDIO_PATH="/Users/myuser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.7199119/Android Studio.app"