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

[亡魂溺海] 提交于 2019-12-11 14:25:03

问题


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?


回答1:


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"
}


来源:https://stackoverflow.com/questions/57350286/how-do-i-set-the-proper-path-to-android-studio-in-ionic-capacitor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!