quasarframework / quasar

Quasar Framework - Build high-performance VueJS user interfaces in record time
https://quasar.dev
MIT License
26.03k stars 3.54k forks source link

Bug: Android Studio not launching when running "quasar build -m capacitor -t android --ide" #17420

Closed ddenev closed 3 months ago

ddenev commented 3 months ago

What happened?

When running the quasar build -m capacitor -t android --ide command, the Android Studio IDE is not launched.

On the other hand, when running a dev build - quasar dev -m capacitor -t android - the IDE is launched without a problem.

After digging into it, the problem seems to come from the following statement in app-vite/lib/modes/capacitor/capacitor-builder.js:

if (this.argv[ 'skip-pkg' ] !== true) {
  if (this.argv.ide === true) {
    await openIde('capacitor', this.quasarConf.bin, target)
    process.exit(0) // <== this is the problematic statement
  }

  if (target === 'ios') {
    await this.#buildIos()
  }
  else {
    await this.#buildAndroid()
  }
}

If I replace process.exit(0) with return, everything works ok - Android Studio is launched.

This is the console output when running with process.exit(0): image

This is the console output when running with return: image

What did you expect to happen?

Expected the IDE to be launched

Reproduction URL

https://codepen.io/ddenev/pen/PorjvGL

How to reproduce?

  1. Setup a Quasar project with Capacitor, as described in https://quasar.dev/quasar-cli-vite/developing-capacitor-apps/preparation
  2. Run quasar build -m capacitor -t android --ide

Note: No reproduction URL provided as this cannot be reproduced on the web, it's a CLI issue.

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

Quasar CLI Commands/Configuration (@quasar/cli | @quasar/app-webpack | @quasar/app-vite), Cordova Mode, Capacitor Mode

Platforms/Browsers

No response

Quasar info output

Operating System - Windows_NT(10.0.22621) - win32/x64
NodeJs - 20.11.0

Global packages
  NPM - 10.8.1
  yarn - 1.22.22
  @quasar/cli - 2.4.1
  @quasar/icongenie - Not installed
  cordova - Not installed

Important local packages
  quasar - 2.16.6 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
  @quasar/app-vite - 1.9.3 -- Quasar Framework App CLI with Vite
  @quasar/extras - 1.16.12 -- Quasar Framework fonts, icons and animations
  eslint-plugin-quasar - Not installed
  vue - 3.4.33 -- The progressive JavaScript framework for building modern web UI.
  vue-router - 4.4.0
  pinia - 2.1.7 -- Intuitive, type safe and flexible Store for Vue
  vuex - Not installed
  vite - 2.9.18 -- Native-ESM powered web dev build tool
  eslint - 8.57.0 -- An AST-based pattern checker for JavaScript.
  electron - Not installed
  electron-packager - Not installed
  @electron/packager - Not installed
  electron-builder - Not installed
  register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
  @capacitor/core - 6.1.1 -- Capacitor: Cross-platform apps with JavaScript and the web
  @capacitor/cli - 6.1.1 -- Capacitor: Cross-platform apps with JavaScript and the web
  @capacitor/android - 6.1.1 -- Capacitor: Cross-platform apps with JavaScript and the web
  @capacitor/ios - 6.1.1 -- Capacitor: Cross-platform apps with JavaScript and the web

Relevant log output

No response

Additional context

I haven't tested, but I suppose the same problem exists with Cordova builder as well.

github-actions[bot] commented 3 months ago

Hi @ddenev! πŸ‘‹

It looks like you provided an invalid or unsupported reproduction URL. Do not use any service other than Codepen, jsFiddle, StackBlitz, Codesandbox, and GitHub. Make sure the URL you provided is correct and reachable. You can test it by visiting it in a private tab, another device, etc. Please edit your original post above and provide a valid reproduction URL as explained.

Without a proper reproduction, your issue will have to get closed.

Thank you for your collaboration. πŸ‘

ddenev commented 3 months ago

I have updated the OP - added a dummy URL since this cannot be reproduced on the web - it is a CLI issue that needs to be run locally on the machine.

yusufkandemir commented 3 months ago

@ddenev a dummy URL won't do any help, the aim is to get a useful reproduction. You can create a GitHub repo in this case, it's one of the options listed. Even if it's a dead simple project, a repro can still help to understand whether there is a problem with the lock file, some basic configuration, certain package versions, etc.

ddenev commented 3 months ago

@yusufkandemir, thanks for replying but I think you haven't read the OP in full. If you pay closer attention to the problem, you will observe that it has nothing to do with the Quasar project itself but is a bug withing the core quasar package. You can simply create a new Quasar project with yarn create quasar and then initialize Capacitor (as I already described in the reproduction steps above). You would also need to install Android Studio in order to be able to reproduce the issue and this is not possible to do in a URL :)

If you still insist on having a URL, I will just create a fresh Quasar project and give you the link to it but again - the problem is NOT related to a project.

Please, do read the investigation I've done above. I've tested it and it works with return.

ddenev commented 3 months ago

Here are the exact steps to reproduce:

  1. yarn create quasar (use Vite and accept defaults)
  2. cd quasar-project
  3. quasar mode add capacitor
  4. quasar build -m capacitor -T android --ide

The result is - IDE is not launched.

yusufkandemir commented 3 months ago

@ddenev I've read your post but I think you haven't read my message and ignoring my open-source maintainer experience. I've seen a lot of cases where some people experience a problem with a freshly created project whereas we can't reproduce the problem when we create one. It sometimes turns out to be some local configuration, a really weird case, order of executing commands, choosing certain features or not. The code you suspect of being incorrect is 2 years old and it has been perfectly working since.

https://github.com/quasarframework/quasar/blob/d51ad0391dd15d94ffbd4a17f8965ddd882528ab/app-vite/lib/helpers/open-ide.js#L133 The Android Studio launch request may be initiated very slowly due to having a slow machine, running programs such as antiviruses which could slow down launching programs, a problem in Windows, or even NodeJS.

My first recommendation is to update Node to v20.16.0 and even try the latest v22. If you have pending Windows updates, do them. Try restarting the machine. If those don't work, please increase the timeout slowly until you find a value that works and share it with us. If it's something acceptable like 400-500, we should be able to update it. However, if it's more than that, I can safely say there is something wrong in your setup.

ddenev commented 3 months ago

@yusufkandemir

I know that it's a 2 years old code, I've seen the git blame.

Again, I would gently insist you read the OP in detail:

  1. You will see that I have clearly stated that when running quasar dev... the IDE is launched and that when running quasar build... the IDE is not launched - this definitely speaks that there is nothing wrong with my machine, programs, Windows, NodeJS, etc., since it is perfectly able to initiate the IDE launch. Also, the machine is powerful enough (Core i7 13th Gen with 32GB RAM).
  2. You will also notice that I have stated that the problem is the process.exit(0) statement - this statement kills the JS process and does not allow the tasks that should run after the build step to run. This is clearly obvious when you look at the screenshots I provided above:
    • with process.exit(0) the output is cut
    • with return the process finishes properly and the output is complete

The fix is pretty simple - just replace the process.exit(0) with return.

I think that increasing the timeout is not a solution - since the process is currently killed and cannot finish properly (see 2 above and the screenshots).

Here is another proof. Please observe this code: https://github.com/quasarframework/quasar/blob/d51ad0391dd15d94ffbd4a17f8965ddd882528ab/app-vite/lib/cmd/build.js#L161-L167

The build() function above calls the openIde function: https://github.com/quasarframework/quasar/blob/d51ad0391dd15d94ffbd4a17f8965ddd882528ab/app-vite/lib/modes/capacitor/capacitor-builder.js#L49-L52

As you can see, build() cannot be resolved since it is killed and therefore nothing in the then() block can be executed: https://github.com/quasarframework/quasar/blob/d51ad0391dd15d94ffbd4a17f8965ddd882528ab/app-vite/lib/cmd/build.js#L161-L205 and there is a lot going on in that block.

When you replace process.exit() with return the build() function will properly return a Promise and it will be properly resolved.

ddenev commented 3 months ago

@yusufkandemir, try to configure an afterBuild hook in your quasar.config.js and you'll see that it is not called.

rstoenescu commented 3 months ago

Just seeing all these messages now. Took care of it for the q/app-vite & q/app-webpack betas. Now backporting to current q/app-vite & q/app-webpack.

yusufkandemir commented 3 months ago

You will see that I have clearly stated that when running quasar dev... the IDE is launched and that when running quasar build... the IDE is not launched - this definitely speaks that there is nothing wrong with my machine

No, because the dev process is an ongoing one, while the build process waits just enough so that the OS starts launching the IDE and then the build process quits. If anything between the Node-OS communication is making it slower, then the situation ends up being the build process exiting before the IDE has been launched successfully.

However, the other points you've raised in your message are valid. The fix is not as simple as changing process.exit(0) to return. As a side effect of addressing the other points, your problem regarding the IDE not opening should also be fixed.

ddenev commented 3 months ago

thank you both @rstoenescu and @yusufkandemir

rstoenescu commented 3 months ago

The afterBuild hook (and everything else that follows the IDE opening) will not (and should not be called) because the process has been interrupted by requesting to manually finalize the build through the IDE.

ddenev commented 3 months ago

yes, that's a fair point, didn't think about that. then I guess, indeed, 300ms is just not enough to allow the IDE launching to be initiated before the process exits.

I also like the build summary (see the 2nd screenshot in the OP above) that was not shown when exiting with process.exit() πŸ™‚

rstoenescu commented 3 months ago

Fix will be available in:

@ddenev Would you be so kind to open up a new ticket for the build summary pls?

ddenev commented 3 months ago

@ddenev Would you be so kind to open up a new ticket for the build summary pls?

sure!