Skip to content

[bug] Android dev fail in Windows #6502

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

Closed
meowtec opened this issue Mar 20, 2023 · 17 comments
Closed

[bug] Android dev fail in Windows #6502

meowtec opened this issue Mar 20, 2023 · 17 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@meowtec
Copy link
Contributor

meowtec commented Mar 20, 2023

Describe the bug

tauri android dev throw an error:

error Command failed with exit code 4294967295.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
       Error Failed to assemble APK: command ["D:\\workspace\\rust\\tauri\\examples\\api\\src-tauri/gen/android\\api\\gradlew.bat", "--stacktrace", "--project-dir", "D:\\workspace\\rust\\tauri\\examples\\api\\src-tauri/gen/android\\api"] exited with code 1
error Command failed with exit code 1.

Gradle output:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:rustBuildX86_64Debug'.
> A problem occurred starting process 'command 'yarn''

...

Caused by: java.io.IOException: Cannot run program "yarn" (in directory "D:\workspace\rust\tauri\examples\api\src-tauri"): CreateProcess error=2, 系统找不到指定的文件 (translated: 'The system cannot find the file specified')。
        at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
        ... 7 more
Caused by: java.io.IOException: CreateProcess error=2, 系统找不到指定的文件 (translated: 'The system cannot find the file specified')。

It means that the gradle process can not find the npm or yarn command, but why?

This did not happen in @tauri-apps/cli@2.0.0-alpha.2

Reproduction

  1. Development in Windows with Node installed.
  2. Clone tauri repo and checkout next branch.
  3. Build CLI + API.
  4. Run yarn tauri android init + yarn tauri android dev at examples/api.

Expected behavior

Android apk should be compiled successfully.

Platform and versions

Environment
  › OS: Windows 10.0.22624 X64
  › Webview2: 111.0.1661.44
  › MSVC: 
      - Visual Studio Community 2022
  › Node.js: 16.19.1
  › npm: 8.19.3
  › pnpm: 7.29.0
  › yarn: 1.22.19
  › rustup: 1.25.2
  › rustc: 1.67.1
  › cargo: 1.67.1
  › Rust toolchain: stable-x86_64-pc-windows-msvc 

Packages
  › @tauri-apps/cli [NPM]: 2.0.0-alpha.3
  › @tauri-apps/api [NPM]: 2.0.0-alpha.1
  › tauri [RUST]: 2.0.0-alpha.4,
  › tauri-build [RUST]: 2.0.0-alpha.2,
  › tao [RUST]: 0.18.0,
  › wry [RUST]: 0.27.0,

App
  › build-type: bundle
  › CSP: style-src 'unsafe-inline' 'self' https://fonts.googleapis.com; default-src 'self' customprotocol: asset:; font-src https://fonts.gstatic.com; img-src 'self' asset: https://asset.localhost blob: data:
  › distDir: ../dist
  › devPath: http://localhost:5173/
  › framework: Svelte
  › bundler: Vite

App directory structure
  ├─ dist
  ├─ isolation-dist
  ├─ node_modules
  ├─ public
  ├─ src
  └─ src-tauri

Stack trace

No response

Additional context

No response

@meowtec meowtec added status: needs triage This issue needs to triage, applied to new issues type: bug labels Mar 20, 2023
@lucasfernog
Copy link
Member

@tauri-apps/cli@2.0.0-alpha.2 used the absolute path to npm or yarn and now we're trying to do things using the PATH instead. But some PATH additions might not be available in the gradlew runner. Can you tell more about your setup? How are you adding yarn to the PATH?

@meowtec
Copy link
Contributor Author

meowtec commented Mar 20, 2023

@lucasfernog
My Node is installed by https://github.com/coreybutler/nvm-windows and seems that duct / gradle can not find it:

A tiny example:

fn main() {
  let env_path = std::env::var("Path").unwrap();
  println!("env Path: {:?}", &env_path);
  duct::cmd("npm", ["-v"]).env("Path", env_path).run().unwrap();
}
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: NotFound, message: "program not found" }'

PATH is like this:

blabla;C:\\Users\\berto\\AppData\\Roaming\\nvm;C:\\Program Files\\nodejs;blabla

C:\\Program Files\\nodejs is linked from C:\Users\berto\AppData\Roaming\nvm\v16.19.1

@meowtec
Copy link
Contributor Author

meowtec commented Mar 20, 2023

I have deleted C:\Program Files\nodejs, reinstall node from nodejs.org, and make sure C:\Program Files\nodejs\ existing in Path variable (for both user environment variables and system environment variables).
It still throw program not found.

@lucasfernog
Copy link
Member

I use fnm and it works well. Maybe you need to configure something so npm is in the PATH?

@lucasfernog
Copy link
Member

What's the contents of C:\Program Files\nodejs btw? Maybe you need to append /bin to it or something like that.

@meowtec
Copy link
Contributor Author

meowtec commented Mar 20, 2023

What's the contents of C:\Program Files\nodejs btw? Maybe you need to append /bin to it or something like that.

There is no bin inside nodejs:

node_modules
corepack
corepack.cmd
install_tools.bat
node.exe
nodevars.bat
node_etw_provider.man
npm
npm.cmd
npx
npx.cmd

I will try fnm instead.

@lucasfernog
Copy link
Member

Try restarting too, I heard you need to restart in order for the environment variables to propagate. It should work with your setup.

@meowtec
Copy link
Contributor Author

meowtec commented Mar 20, 2023

@lucasfernog I tried with fnm but still failed, here are my steps:

  1. reinstall node.js
  2. install fnm using choco install fnm
  3. setup powershell by adding fnm env --use-on-cd | Out-String | Invoke-Expression to $PROFILE
  4. restart Windows

Now npm and the environment variables are correct, I think

PS C:\Users\berto> npm -v
9.5.0

Get-Command npm
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     npm.cmd                                            0.0.0.0    C:\Users\xxx\AppData\Local\fnm_multishells\xxx\npm.cmd

Gradle and duct still do not find npm.

But I found a workaround: change npm to npm.cmd.

duct::cmd("npm.cmd", ["-v"]).run().unwrap();
project.exec {
    workingDir(File(project.projectDir, rootDirRel.path))
    executable("""npm.cmd""")
    args(listOf("run", "tauri", "--", "android", "android-studio-script"))
    if (project.logger.isEnabled(LogLevel.DEBUG)) {
        args("-vv")
    } else if (project.logger.isEnabled(LogLevel.INFO)) {
        args("-v")
    }
    if (release) {
        args("--release")
    }
    args(listOf("--target", target))
}.assertNormalExitValue()

They work.

std::process::Command has same behaviour:

    use std::process::Command;
    // will get `program not found` error
    // if change `npm` to `npm.cmd` it will get `Ok`
    let mut child = Command::new("npm")
        .arg("-v")
        .spawn()
        .expect("failed to execute child");

    let ecode = child.wait().expect("failed to wait on child");

@meowtec
Copy link
Contributor Author

meowtec commented Mar 20, 2023

But I run into a new problem:
The dev command started without any error, but nothing appears in my Android simulator - No app launched.

<-------------> 0% EXECUTING [8s]
> :app:rustBuildX86_64Debug                   Compiling wry v0.27.0TING [10s]
   Compiling tauri-runtime-wry v0.13.0-alpha.2 (D:\workspace\rust\tauri\core\tauri-runtime-wry)
   Compiling tauri v2.0.0-alpha.4 (D:\workspace\rust\tauri\core\tauri)
   Compiling tauri-plugin-log v0.1.0 (https://github.com/tauri-apps/plugins-workspace?branch=next#39b144df)
   Compiling tauri-plugin-sample v0.1.0 (D:\workspace\rust\tauri\examples\api\src-tauri\tauri-plugin-sample)
   Compiling api v0.1.0 (D:\workspace\rust\tauri\examples\api\src-tauri)
    Finished dev [unoptimized + debuginfo] target(s) in 7.65s
        Info symlinking lib "D:\\workspace\\rust\\tauri\\examples\\api\\src-tauri\\target\\x86_64-linux-android\\debug\\libapi.so" in jniLibs dir "D:\\workspace\\rust\\tauri\\examples\\api\\src-tauri/gen/android\\api\\app/src/main/jniLibs/x86_64"
        Info "D:\\workspace\\rust\\tauri\\examples\\api\\src-tauri\\target\\x86_64-linux-android\\debug\\libapi.so" requires shared lib "liblog.so"
        Info "D:\\workspace\\rust\\tauri\\examples\\api\\src-tauri\\target\\x86_64-linux-android\\debug\\libapi.so" requires shared lib "libandroid.so"
        Info "D:\\workspace\\rust\\tauri\\examples\\api\\src-tauri\\target\\x86_64-linux-android\\debug\\libapi.so" requires shared lib "libdl.so"
        Info "D:\\workspace\\rust\\tauri\\examples\\api\\src-tauri\\target\\x86_64-linux-android\\debug\\libapi.so" requires shared lib "libm.so"
        Info "D:\\workspace\\rust\\tauri\\examples\\api\\src-tauri\\target\\x86_64-linux-android\\debug\\libapi.so" requires shared lib "libc.so"
<-------------> 0% EXECUTING [1m 23s]
> :app:rustBuildX86_64Debug

@lucasfernog
Copy link
Member

My Windows VM is broken but I'm opening a PR to fix the .cmd thing, can you help test it?
@amrbashir can you see if there's something wrong with the emulator on Windows?

@meowtec
Copy link
Contributor Author

meowtec commented Mar 20, 2023

My Windows VM is broken but I'm opening a PR to fix the .cmd thing, can you help test it? @amrbashir can you see if there's something wrong with the emulator on Windows?

I will test it 20 hours later.

@amrbashir
Copy link
Member

worked fine for me, can you try recreating the android project, clearing the target folder and potentially any old apks on the emulator with the same bundler identifier?

I did encounter another bug but that bug will crash the CLI and it is with pnpm, so I am gonna assume it is not related to this, but here is the error in case you run into it:


> tauri-app@0.0.0 tauri D:\dev\tauri-app
> tauri "--" "android" "android-studio-script" "--target" "x86_64"

error: unexpected argument 'android' found

  note: subcommand 'android' exists; to use it, remove the '--' before it

Usage: pnpm run tauri [OPTIONS] <COMMAND>

For more information, try '--help'.
?ELIFECYCLE? Command failed with exit code 2.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:rustBuildX86_64Debug'.
> Process 'command 'pnpm'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
 ELIFECYCLE  Command failed with exit code 4294967295.
       Error Failed to assemble APK: command ["D:\\dev\\tauri-app\\src-tauri/gen/android\\tauri_app\\gradlew.bat", "--project-dir", "D:\\dev\\tauri-app\\src-tauri/gen/android\\tauri_app"] exited with code 1

@amrbashir
Copy link
Member

After fixing the above pnpm error I quickly ran into the same issue. I think the CLI when invoked from pnpm, yarn or npm, it never exists and instead it hangs up indefinitely. I encountered the same issue with pnpm tauri android init.

@amrbashir
Copy link
Member

I have no idea why it hangs but the commands are executed and resolved back to the JS cli, yet the process doesn't exit. Exiting the process manually on successful commands fixes it. I opened #6510 for this.

@meowtec
Copy link
Contributor Author

meowtec commented Mar 21, 2023

I have no idea why it hangs but the commands are executed and resolved back to the JS cli, yet the process doesn't exit. Exiting the process manually on successful commands fixes it. I opened #6510 for this.

The process doesn't exit because of a bug napi@2.11.4. It has been fixed but the author have not released a new version for that.

@amrbashir
Copy link
Member

Ah nice, looks like it got released today.

@amrbashir
Copy link
Member

this should be fixed now in the latest tauri-cli 2.0.0-alpha.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

3 participants