KRTirtho / metadata_god

Audio file Metadata reading and writing library for Flutter
MIT License
23 stars 12 forks source link

How to build for Android? #9

Closed licaon-kter closed 1 year ago

licaon-kter commented 1 year ago
.../metadata_god_rust$ bash ./scripts/build-android.sh
mkdir: cannot create directory ‘platform-build’: File exists
    Updating crates.io index
     Ignored package `cargo-ndk v3.0.1` is already installed, use --force to override
info: component 'rust-std' for target 'aarch64-linux-android' is up to date
info: component 'rust-std' for target 'armv7-linux-androideabi' is up to date
info: component 'rust-std' for target 'x86_64-linux-android' is up to date
info: component 'rust-std' for target 'i686-linux-android' is up to date
[2023-04-11T09:50:42Z INFO  cargo_ndk::cli] Using NDK at path: /opt/android-sdk/ndk/25.1.8937393 (ANDROID_NDK_ROOT)
[2023-04-11T09:50:42Z INFO  cargo_ndk::cli] NDK API level: 21
[2023-04-11T09:50:42Z INFO  cargo_ndk::cli] Building targets: armeabi-v7a, arm64-v8a, x86, x86_64
[2023-04-11T09:50:42Z INFO  cargo_ndk::cli] Building armeabi-v7a (armv7-linux-androideabi)
   Compiling metadata_god v0.4.1 (/home/vagrant/build/srclib/metadata_god_rust/packages/metadata_god/native)
error: failed to run custom build command for `metadata_god v0.4.1 (/home/vagrant/build/srclib/metadata_god_rust/packages/metadata_god/native)`

Caused by:
  process didn't exit successfully: `/home/vagrant/build/srclib/metadata_god_rust/target/release/build/metadata_god-f7b862824068f321/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=src/api.rs

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: missing pubspec.lock in /home/vagrant/build/srclib/metadata_god_rust/packages/metadata_god/native/..', packages/metadata_god/native/build.rs:30:43
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2023-04-11T09:50:43Z INFO  cargo_ndk::cli] If the build failed due to a missing target, you can run this command:
[2023-04-11T09:50:43Z INFO  cargo_ndk::cli] 
[2023-04-11T09:50:43Z INFO  cargo_ndk::cli]     rustup target install armv7-linux-androideabi

Which folder exactly I should be running the script in?

KRTirtho commented 1 year ago

Last time there were no good ways of building, so I made a couple changes.

Install melos and cargo-ndk Make sure appropriate android-ndk is installed. You can find the version here as static String ndkVersion =....

$ cargo install cargo-ndk
$ flutter pub global activate melos

Now bootstrap the project deps, build library and copy the shared objects

$ melos bs
$ melos build:android
$ melos copylib:android

All of this should be ran on the root of the package directory

licaon-kter commented 1 year ago

Thanks