rust-mobile / cargo-apk

Helps cargo build APKs
Apache License 2.0
97 stars 26 forks source link

`cargo apk build` gives `No such file...` without further info #48

Open TomMD opened 7 months ago

TomMD commented 7 months ago

In a nut shell:

~/dev/rust-android-examples/na-mainloop]$ cargo apk build
Using package `na-mainloop` in `/home/tommd/dev/rust-android-examples/na-mainloop/Cargo.toml`
Error: No such file or directory (os error 2)

This is after a system setup which I tried to capture:

  1. Have rustup and java jdk:
$ nix-shell -p jdk -p rustup
  1. Download the 'commandline only' tools (https://developer.android.com/studio) and use sdkmanager to get the sdk unzip thing and cd in then
$ export ANDROID_HOME=$(pwd)
$ $ANDROID_HOME/bin/sdkmanager --sdk_root=$ANDROID_HOME --install "build-tools;34.0.0" "cmdline-tools;latest" "extras;android;m2repository" "ndk;26.1.10909125" "platforms;android-31"

(Notice the 'ANDROID_SDK_HOME' envvar is deprecated, contrary to the readme)

  1. Download the NDK (https://developer.android.com/ndk/downloads) unzip thing and cd
$ export ANDROID_NDK_HOME=$(pwd)
  1. Run a demo (https://github.com/rust-mobile/rust-android-examples/tree/main/na-mainloop)
$ rustup default 1.70.0
$ rustup target install aarch64-linux-android
$ git clone https://github.com/rust-mobile/rust-android-examples
$ cd rust-android-examples/na-mainloop
$ cargo install cargo-ndk
$ cargo ndk -t arm64-v8a -o app/src/main/jniLibs/  build
$ cargo install cargo-apk
$ cargo apk build
Using package `na-mainloop` in `..../dev/rust-android-examples/na-mainloop/Cargo.toml`
Error: No such file or directory (os error 2)
MarijnS95 commented 7 months ago

Moving this to cargo-apk because the issue described is either a build system issue, or a rust-android-examples (via android-activity) example setup/documentation issue. Neither of which relate to the native libandroid.so (and friends) bindings provided by the ndk crate.

rednaz1337 commented 5 months ago

strace tells me this:

openat(AT_FDCWD, "/home/hz/programmieren/rust/my-project/target/aarch64-linux-android/debug/build", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (Datei oder Verzeichnis nicht gefunden)

I have a global cargo target directory configured in ~/.cargo/config.toml. As a workaround I created a cargo config in my project directory, which sets build.target-dir = "target". This fixes the issue for me.

MarijnS95 commented 5 months ago

@rednaz1337 that must originate from the following snippet:

https://github.com/rust-mobile/cargo-apk/blob/caa806283dc26733ad8232dce1fa4896c566f7b8/ndk-build/src/dylibs.rs#L11-L14

While target-dir is parsed from .cargo/confg.toml, as you found it is currently only detected in the package workspace, but not up-merged from parent directories and ultimately the global home folder config based on this structure: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure

This TODO is ""tracked"" at https://github.com/rust-mobile/cargo-subcommand/blob/de0458c0cedfad69717fbbc09a2ef23226318e10/src/subcommand.rs#L83-L88.