How do I set the proper path to Android Studio in Ionic/Capacitor?
Asked Answered
T

2

6

I'm working through an Ionic/React getting-started, on my Linux Mint box.

Building an Ionic application using React

The first steps went well enough, but when I get to Deploying your application to iOS and Android Step 5, I get errors.

The instructions:

Open your project in Android Studio using the following command:

    npx cap open android

First I got pathing errors:

events.js:174
    throw er; // Unhandled 'error' event
    ^

Error: spawn /usr/local/android-studio/bin/studio.sh 
ENOENT

That seemed simple enough. That's not where android studio is installed on my machine.

I did some googling around, and some grepping in node_modules, and discovered the "androidStudioPath" setting. I tried adding it to my project's capacitor.config.json file, and it made no difference. So I looked at the code a bit more carefully, and then added it in a "linux" object:

{
    "appId": "us.jdege.mytestapp",
    "appName": "mytestapp",
    "bundledWebRuntime": false,
    "npmClient": "npm",
    "webDir": "build",
    "linux": {
        "androidStudioPath": "/var/.../studio.sh"
    }
}

From all I can tell, this is the right setting, and I'm setting the right path. But it's being ignored.

jdege@linux-2016 ~/react-projects/mytestapp $ npx cap open android
[info] Opening Android project at /home/jdege/react-projects/mytestapp/android
events.js:174
    throw er; // Unhandled 'error' event
    ^

Error: spawn /usr/local/android-studio/bin/studio.sh ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
    at onErrorNT (internal/child_process.js:415:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)

How do I set the proper path to Android Studio in Ionic/Capacitor?

Treiber answered 4/8, 2019 at 21:19 Comment(0)
T
17

Use the source, Luke!

The proper setting is "linuxAndroidStudioPath".

In ./node_modules/@capacitor/cli/dist/android/open.js, you'll find:

common_1.logError('Unable to launch Android Studio. You must configure "linuxAndroidStudioPath" ' +
'in your capacitor.config.json to point to the location of studio.sh, using JavaScript-escaped paths:\n' +
'Example:\n' +
'{\n' +
'  "linuxAndroidStudioPath": "/usr/local/android-studio/bin/studio.sh"\n' +
'}');

So while in ./capacitor.config.json this doesn't work:

{
    ...
    "androidStudioPath": "/var/.../studio.sh"
}

And this doesn't work:

{
    ...
    "linux": {
        "androidStudioPath": "/var/.../studio.sh"
    }
}

This does:

{
    ...
    "linuxAndroidStudioPath": "/var/.../studio.sh"
}
Treiber answered 4/8, 2019 at 22:53 Comment(1)
But how can I configure for multiple developers which uses different paths depending on its OS? This file is shared, so it can be committed by each developer. Using CAPACITOR_ANDROID_STUDIO_PATH didn't work.Odilia
A
4

I use JetBrains Toolbox to manage my Android Studio on my macOS

to use npx cap open android I had to export the Android Studio path as follow:

export CAPACITOR_ANDROID_STUDIO_PATH="/Users/myuser/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/201.7199119/Android Studio.app" 
Acetylcholine answered 13/4, 2021 at 15:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.