在Ionic 5中CAPACITOR_ANDROID_STUDIO_PATH环境变量的含义是什么?

5
尝试添加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 时,CapacitorConfigPluginsConfig 都无法工作, 它显示了这个问题。

    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 文件中,我已使用 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"
    }
  }
}

现在Angular 10使用.ts扩展名,而Angular 12现在使用capacitor.config.ts。那么我该如何实现类似于这样的内容:"windowsAndroidStudioPath": "D:\\android-studio-canary\\bin\\studio64.exe"
2个回答

8
在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

OP在问题中使用“windowsAndroidStudioPath”作为旧配置。你的解决方案是针对Ubuntu的,所以很遗憾它并没有帮助到他。 - nCr78
@nCr78 其他人仍然可以从这个回答中受益。 - Evan
要获取您的Android路径,请运行以下命令:whereis studio.sh - Raju Sah
1
在执行第一个命令后,你需要运行 source ~/.bashrc 或者 source ~/.zshrc(如果你使用的是 zsh),或者重新启动终端,以使其生效。 - undefined

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


{ "appId": "io.ionic.starter.Udemy.Course", "appName": "ionic-angular-course", "bundledWebRuntime": false, "npmClient": "npm", "webDir": "www", "windowsAndroidStudioPath": "D:\android-studio-canary\bin\studio64.exe", "plugins": { "SplashScreen": { "launchShowDuration": 0 } }, "cordova": {}, "server": { "cleartext": true, "url": "http://192.168.1.10:8101" } }我之前使用过这段代码,现在我该如何在 Angular 12 中使用它? - user10668235
这部分是关于Angular 10的,我已经展示了。 - user10668235

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接