user10668235
user10668235

Reputation:

CAPACITOR_ANDROID_STUDIO_PATH environment variable in Ionic 5

Tried to add CAPACITOR_ANDROID_STUDIO_PATH environment variable as.

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;

If I try to add it in the.

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

will give error as this. enter image description here

ionic build works but when I run npx cap open android both of them CapacitorConfig and PluginsConfig doesn't work it shows this problem.

    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.

I referenced it from here.
https://capacitorjs.com/docs/config

Update 1: In capacitor.config.json I've used 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"
    }
  }
}

For Angular 10 now for Angular 12 is using as .ts extension for capacitor.config.ts now how do I implement something like this "windowsAndroidStudioPath": "D:\\android-studio-canary\\bin\\studio64.exe".

Upvotes: 6

Views: 24660

Answers (2)

Yurii Hierts
Yurii Hierts

Reputation: 1930

On Ubuntu 16.04 export this variable in .bashrc file

echo export CAPACITOR_ANDROID_STUDIO_PATH="custom-path/android-studio/bin/studio.sh" >> ~/.bashrc
source ~/.bashrc

Or just run before ionic cap open android

export CAPACITOR_ANDROID_STUDIO_PATH="custom-path/android-studio/bin/studio.sh"
ionic cap open android

Upvotes: 10

Rami Assi
Rami Assi

Reputation: 1129

Environment variables are configured in your operating system not in your App.

CAPACITOR_ANDROID_STUDIO_PATH: The path to Android Studio executable on your system. https://capacitorjs.com/docs/config#environment-variables

if you like to know how to set environment variables in Windows you can refer to:

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

if you like to know how to set environment variables in Linux Ubuntu you can refer to:

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

Upvotes: 0

Related Questions