Issue
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?
Solution
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"
}
Answered By - Jeff Dege
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.