Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ddenev opened this issue Aug 7, 2024 · 15 comments

Comments

@ddenev
Copy link
Contributor

ddenev commented Aug 7, 2024

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.

Copy link

github-actions bot commented Aug 7, 2024

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
Copy link
Contributor Author

ddenev commented Aug 7, 2024

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
Copy link
Member

@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
Copy link
Contributor Author

ddenev commented Aug 7, 2024

@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
Copy link
Contributor Author

ddenev commented Aug 7, 2024

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
Copy link
Member

@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.

setTimeout(resolve, 300)

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
Copy link
Contributor Author

ddenev commented Aug 7, 2024

@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:

appBuilder.build()
.catch(err => {
console.error(err)
fatal('App build failed (check the log above)', 'FAIL')
})
.then(async () => {
artifacts.add(outputFolder)

The build() function above calls the openIde function:

if (this.argv.ide === true) {
await openIde('capacitor', this.quasarConf.bin, target)
process.exit(0)
}

As you can see, build() cannot be resolved since it is killed and therefore nothing in the then() block can be executed:

appBuilder.build()
.catch(err => {
console.error(err)
fatal('App build failed (check the log above)', 'FAIL')
})
.then(async () => {
artifacts.add(outputFolder)
outputFolder = argv.mode === 'cordova'
? path.join(outputFolder, '..')
: outputFolder
banner(argv, 'build', {
buildOutputFolder: outputFolder,
target: quasarConf.build.target
})
if (typeof quasarConf.build.afterBuild === 'function') {
await quasarConf.build.afterBuild({ quasarConf })
}
// run possible beforeBuild hooks
await extensionRunner.runHook('afterBuild', async hook => {
log(`Extension(${ hook.api.extId }): Running afterBuild hook...`)
await hook.fn(hook.api, { quasarConf })
})
if (argv.publish !== void 0) {
const opts = {
arg: argv.publish,
distDir: outputFolder,
quasarConf
}
if (typeof quasarConf.build.onPublish === 'function') {
await quasarConf.build.onPublish(opts)
}
// run possible onPublish hooks
await extensionRunner.runHook('onPublish', async hook => {
log(`Extension(${ hook.api.extId }): Running onPublish hook...`)
await hook.fn(hook.api, opts)
})
}
})

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
Copy link
Contributor Author

ddenev commented Aug 7, 2024

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

rstoenescu added a commit that referenced this issue Aug 7, 2024
…t being launched when running "quasar build -m capacitor -T android --ide" #17420
rstoenescu added a commit that referenced this issue Aug 7, 2024
… not being launched when running "quasar build -m capacitor -T android --ide" #17420
@rstoenescu rstoenescu self-assigned this Aug 7, 2024
@rstoenescu
Copy link
Member

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
Copy link
Member

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
Copy link
Contributor Author

ddenev commented Aug 7, 2024

thank you both @rstoenescu and @yusufkandemir

@rstoenescu
Copy link
Member

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
Copy link
Contributor Author

ddenev commented Aug 7, 2024

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 added a commit that referenced this issue Aug 7, 2024
…n Windows host -> Android Studio not being launched when running "quasar build -m capacitor -T android --ide" #17420
rstoenescu added a commit that referenced this issue Aug 7, 2024
…dova on Windows host -> Android Studio not being launched when running "quasar build -m capacitor -T android --ide" #17420
@rstoenescu
Copy link
Member

Fix will be available in:

  • q/app-vite v2.0.0-beta.19
  • q/app-webpack v4.0.0-beta.20
  • q/app-vite v1.9.5
  • q/app-webpack v3.13.4

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

@ddenev
Copy link
Contributor Author

ddenev commented Aug 7, 2024

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

sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants