tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
82.35k stars 2.47k forks source link

[bug] cargo tauri android dev not working correctly #7314

Open StormLight14 opened 1 year ago

StormLight14 commented 1 year ago

Describe the bug

I run cargo tauri android dev, and get this error

Info detected host target triple "x86_64-unknown-linux-gnu"
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
        Info symlinking lib "/home/storm/Documents/Rust_Projects/apps/base64-converter/target/x86_64-linux-android/debug/libapp_lib.so" in jniLibs dir "/home/storm/Documents/Rust_Projects/apps/base64-converter/src-tauri/gen/android/app/src/main/jniLibs/x86_64"
        Info "/home/storm/Documents/Rust_Projects/apps/base64-converter/target/x86_64-linux-android/debug/libapp_lib.so" requires shared lib "libandroid.so"
        Info "/home/storm/Documents/Rust_Projects/apps/base64-converter/target/x86_64-linux-android/debug/libapp_lib.so" requires shared lib "libdl.so"
        Info "/home/storm/Documents/Rust_Projects/apps/base64-converter/target/x86_64-linux-android/debug/libapp_lib.so" requires shared lib "liblog.so"
        Info "/home/storm/Documents/Rust_Projects/apps/base64-converter/target/x86_64-linux-android/debug/libapp_lib.so" requires shared lib "libm.so"
        Info "/home/storm/Documents/Rust_Projects/apps/base64-converter/target/x86_64-linux-android/debug/libapp_lib.so" requires shared lib "libc.so"
        Info symlink at "/home/storm/Documents/Rust_Projects/apps/base64-converter/src-tauri/gen/android/app/src/main/jniLibs/x86_64/libapp_lib.so" points to "/home/storm/Documents/Rust_Projects/apps/base64-converter/target/x86_64-linux-android/debug/libapp_lib.so"
error: unrecognized subcommand '/home/storm/Documents/Rust_Projects/apps/base64-converter/android'

Usage: cargo tauri [OPTIONS] <COMMAND>

For more information, try '--help'.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:rustBuildX86_64Debug'.
> Process 'command '/home/storm/.cargo/bin/cargo-tauri'' finished with non-zero exit value 2

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/8.0/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s
       Error Failed to assemble APK: command ["/home/storm/Documents/Rust_Projects/apps/base64-converter/src-tauri/gen/android/gradlew", "--project-dir", "/home/storm/Documents/Rust_Projects/apps/base64-converter/src-tauri/gen/android"] exited with code 1

I saw the shared lib stuff and after locating the files it says it requires, this directory has them: /home/storm/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/x86_64-linux-android/33/ I tried some stuff but it never changed, im not sure if it's an error at all or if something else is the issue since it just says "Info"

Reproduction

No response

Expected behavior

No errors, app opens in emulator.

Platform and versions

[✔] Environment
    - OS: Arch Linux Rolling Release X64
    ✔ webkit2gtk-4.1: 2.40.2
    ✔ rsvg2: 2.56.1
    ✔ rustc: 1.69.0 (84c898d65 2023-04-16)
    ✔ Cargo: 1.69.0 (6e9a83356 2023-04-12)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (environment override by RUSTUP_TOOLCHAIN)
    - node: 20.3.0
    - yarn: 1.22.19
    - npm: 8.19.2

[-] Packages
    - tauri [RUST]: 2.0.0-alpha.10
    - tauri-build [RUST]: 2.0.0-alpha.6
    - wry [RUST]: 0.28.3
    - tao [RUST]: 0.19.1
    - @tauri-apps/api [NPM]: not installed!
    - @tauri-apps/cli [NPM]: 2.0.0-alpha.10

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist
    - devPath: http://0.0.0.0:1421/

Stack trace

No response

Additional context

idk if I did this correctly, i just got told to put this in issues so sorry if it's wrong

amrbashir commented 1 year ago

Could you show the contents of src-tauri\gen\android\buildSrc\src\main\java\com\tauri\tauri_app_mobile\kotlin\BuildTask.kt

StormLight14 commented 1 year ago

Yep, sorry for the late reply!

import java.io.File
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.logging.LogLevel
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction

open class BuildTask : DefaultTask() {
    @Input
    var rootDirRel: String? = null
    @Input
    var target: String? = null
    @Input
    var release: Boolean? = null

    @TaskAction
    fun assemble() {
        val executable = """/home/storm/.cargo/bin/cargo-tauri""";
        try {
            runTauriCli(executable)
        } catch (e: Exception) {
            if (Os.isFamily(Os.FAMILY_WINDOWS)) {
                runTauriCli("$executable.cmd")
            } else {
                throw e;
            }
        }
    }

    fun runTauriCli(executable: String) {
        val rootDirRel = rootDirRel ?: throw GradleException("rootDirRel cannot be null")
        val target = target ?: throw GradleException("target cannot be null")
        val release = release ?: throw GradleException("release cannot be null")
        val args = listOf("tauri", "/home/storm/Documents/Rust_Projects/base64-converter/android", "init", "android-studio-script");

        project.exec {
            workingDir(File(project.projectDir, rootDirRel))
            executable(executable)
            args(args)
            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()
    }
}
amrbashir commented 1 year ago

that's really weird, could you try removing src-tauri/gen and run cargo android init again and see if it is fixed? Otherwise, I will need some steps to reproduce

StormLight14 commented 1 year ago

Before that, I have one suspicion of what it could be. I had an issue where the file x86_64-linux-android-ranlib couldn't be found, and when i asked elsewhere someone said llvm-ranlib which was in the path ~/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/bin/ is the same thing and just to rename it to be the name of the file, and I don't know if this is actually true. Renaming it did make the error a lot smaller though.

amrbashir commented 1 year ago

I'd recommend creating a new project using create-tauri-app and see if the issue persists, if it does, let me know the steps you made