Ionic 5 中的 CAPACITOR_ANDROID_STUDIO_PATH 环境变量

6 typescript ionic-framework angular ionic5 angular12

尝试添加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;
Run Code Online (Sandbox Code Playgroud)

如果我尝试将其添加到 .

const config: CapacitorConfig = {
  appId: 'com.barqrscanner.app',
  appName: 'barqrscannerapp',
  webDir: 'www',
  bundledWebRuntime: false,
  CAPACITOR_ANDROID_STUDIO_PATH: 'D:\\android-studio-canary\\bin\\studio64.exe'
};
Run Code Online (Sandbox Code Playgroud)

会给出这样的错误。 在此输入图像描述

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.
Run Code Online (Sandbox Code Playgroud)

我从这里引用了它。
https://capacitorjs.com/docs/config

更新1:capacitor.config.json我用过as。

{
  "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"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

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

Yur*_*rts 9

在 Ubuntu 16.04 上将此变量导出到 .bashrc 文件中

echo export CAPACITOR_ANDROID_STUDIO_PATH="custom-path/android-studio/bin/studio.sh" >> ~/.bashrc
source ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

或者只是之前运行ionic cap open android

export CAPACITOR_ANDROID_STUDIO_PATH="custom-path/android-studio/bin/studio.sh"
ionic cap open android
Run Code Online (Sandbox Code Playgroud)


Ram*_*ssi 0

环境变量是在您的操作系统中配置的,而不是在您的应用程序中配置的。

CAPACITOR_ANDROID_STUDIO_PATH:系统上 Android Studio 可执行文件的路径。 https://capacitorjs.com/docs/config#environment-variables

如果您想了解如何在Windows中设置环境变量可以参考:

https://learn.microsoft.com/en-us/answers/questions/26223/environment-variable.html

如果你想了解如何在Linux Ubuntu中设置环境变量可以参考:

https://help.ubuntu.com/community/EnvironmentVariables