尝试添加CAPACITOR_ANDROID_STUDIO_PATH环境变量。
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.barqrscanner.app',
appName: 'barqrscannerapp',
webDir: 'www',
bundledWebRuntime: false
};
export interface PluginsConfig {
[CAPACITOR_ANDROID_STUDIO_PATH: string]: | {
[CAPACITOR_ANDROID_STUDIO_PATH: string]: 'D:\\android-studio-canary\\bin\\studio64.exe';
}
| undefined;
}
export default config;如果我试图将它添加到。
const config: CapacitorConfig = {
appId: 'com.barqrscanner.app',
appName: 'barqrscannerapp',
webDir: 'www',
bundledWebRuntime: false,
CAPACITOR_ANDROID_STUDIO_PATH: 'D:\\android-studio-canary\\bin\\studio64.exe'
};就会产生错误。

ionic build可以工作,但是当我运行npx cap open android时- CapacitorConfig和PluginsConfig -都不能工作,这说明了这个问题。
PS D:\Projects\BarQrScannerApp> npx cap open android
[error] Unable to launch Android Studio. Is it installed?
Attempted to open Android Studio at:
You can configure this with the CAPACITOR_ANDROID_STUDIO_PATH environment variable.我是从这里引用的。
https://capacitorjs.com/docs/config
更新1:我用过的capacitor.config.json中的。
{
"appId": "com.enappd.capBarcodeScanner",
"appName": "ionic-capacitor-barcode-scanner",
"bundledWebRuntime": false,
"npmClient": "npm",
"webDir": "www",
"windowsAndroidStudioPath": "D:\\android-studio-canary\\bin\\studio64.exe",
"cordova": {
"preferences": {
"ScrollEnabled": "false",
"android-minSdkVersion": "19",
"BackupWebStorage": "none",
"SplashMaintainAspectRatio": "true",
"FadeSplashScreenDuration": "300",
"SplashShowOnlyFirstTime": "false",
"SplashScreen": "screen",
"SplashScreenDelay": "3000"
}
}
}对于角10,现在对于角12是capacitor.config.ts的capacitor.config.ts扩展,现在我如何实现类似于"windowsAndroidStudioPath": "D:\\android-studio-canary\\bin\\studio64.exe"的东西。
发布于 2021-09-11 09:50:15
在Ubuntu16.04上导出.bashrc文件中的这个变量
echo export CAPACITOR_ANDROID_STUDIO_PATH="custom-path/android-studio/bin/studio.sh" >> ~/.bashrc或者在ionic cap open android之前运行
export CAPACITOR_ANDROID_STUDIO_PATH="custom-path/android-studio/bin/studio.sh"
ionic cap open android发布于 2021-06-20 18:03:56
环境变量是在操作系统中配置的,而不是在应用程序中配置的。
CAPACITOR_ANDROID_STUDIO_PATH:在您的系统上到Android可执行文件的路径。https://capacitorjs.com/docs/config#environment-variables
如果您想知道如何在Windows中设置环境变量,可以参考:
https://learn.microsoft.com/en-us/answers/questions/26223/environment-variable.html
如果您想知道如何在Linux中设置环境变量,可以参考:
https://stackoverflow.com/questions/68058470
复制相似问题