首页 > 解决方案 > Ionic 5 中的 CAPACITOR_ANDROID_STUDIO_PATH 环境变量

问题描述

试图将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"
    }
  }
}

对于 Angular 10,现在 Angular 12 正在用作.ts扩展,capacitor.config.ts我该如何实现这样的东西"windowsAndroidStudioPath": "D:\\android-studio-canary\\bin\\studio64.exe"

标签: angulartypescriptionic-frameworkionic5angular12

解决方案


在 Ubuntu 16.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

推荐阅读