admin管理员组

文章数量:1410674

I am trying to build a rust library as a .so file output to run it on android.

This is my cargo.toml:

[package]
name = "my_project"
version = "0.1.0"
edition = "2021"

[lib]
name = "my_project"
crate-type = ["cdylib"]

[dependencies]
android_logger = "0.14.1"
cpal = "0.15.3"
jni = "0.21.1"
lazy_static = "1.5.0"
log = "0.4.25"
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.138"
tokio = { version = "1", features = ["full"] }
opus = "0.3.0"

As can be observed I have used opus library which works fine on my linux machine but when I compile it using cargo ndk it always crashes the command I use cargo ndk -t arm64-v8a build I tried for other architectures to like aarch64 android and others but opus build always fails with output:

error: failed to run custom build command for `audiopus_sys v0.2.2`

Caused by:
  process didn't exit successfully: `/home/riyan/Project/lib_nav_companion/target/debug/build/audiopus_sys-46192d6fb355b689/build-script-build` (exit status: 101)
  --- stdout
  cargo:info=No feature or environment variable found, linking by default.
  cargo:rerun-if-env-changed=OPUS_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64-linux-android
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_linux_android
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-linux-android
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_linux_android
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-linux-android
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_linux_android
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:info=`pkg_config` could not find `Opus`.
  cargo:info=Opus source path used: "/home/riyan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/audiopus_sys-0.2.2/opus".
  cargo:info=Building Opus via CMake.
  CMAKE_TOOLCHAIN_FILE_aarch64-linux-android = None
  CMAKE_TOOLCHAIN_FILE_aarch64_linux_android = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_aarch64-linux-android = None
  CMAKE_GENERATOR_aarch64_linux_android = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  CMAKE_PREFIX_PATH_aarch64-linux-android = None
  CMAKE_PREFIX_PATH_aarch64_linux_android = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_aarch64-linux-android = None
  CMAKE_aarch64_linux_android = None
  TARGET_CMAKE = None
  CMAKE = None
  running: cd "/home/riyan/Project/lib_nav_companion/target/aarch64-linux-android/debug/build/audiopus_sys-9b0abebfac756f4c/out/build" && CMAKE_PREFIX_PATH="" LC_ALL="C" "cmake" "/home/riyan/.cargo/registry/src/index.crates.io-1949cf8c6b5
b557f/audiopus_sys-0.2.2/opus" "-DCMAKE_SYSTEM_NAME=Android" "-DCMAKE_SYSTEM_PROCESSOR=aarch64" "-DCMAKE_INSTALL_PREFIX=/home/riyan/Project/lib_nav_companion/target/aarch64-linux-android/debug/build/audiopus_sys-9b0abebfac756f4c/out" "-DC
MAKE_C_FLAGS= -DANDROID -ffunction-sections -fdata-sections -fPIC --target=aarch64-linux-android --target=aarch64-linux-android21" "-DCMAKE_C_COMPILER=/home/riyan/Android/Sdk/ndk/29.0.13113456/toolchains/llvm/prebuilt/linux-x86_64/bin/cla
ng" "-DCMAKE_CXX_FLAGS= -DANDROID -ffunction-sections -fdata-sections -fPIC --target=aarch64-linux-android --target=aarch64-linux-android21" "-DCMAKE_CXX_COMPILER=/home/riyan/Android/Sdk/ndk/29.0.13113456/toolchains/llvm/prebuilt/linux-x8
6_64/bin/clang++" "-DCMAKE_ASM_FLAGS= -DANDROID -ffunction-sections -fdata-sections -fPIC --target=aarch64-linux-android --target=aarch64-linux-android21" "-DCMAKE_ASM_COMPILER=/home/riyan/Android/Sdk/ndk/29.0.13113456/toolchains/llvm/pre
built/linux-x86_64/bin/clang" "-DCMAKE_BUILD_TYPE=Debug"
  -- Opus project version: 0
  -- Configuring incomplete, errors occurred!

  --- stderr
  CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
    Compatibility with CMake < 3.10 will be removed from a future version of
    CMake.

    Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
    to tell CMake that the project requires at least <min> but has been updated
    to work with policies introduced by <max> or earlier.


  CMake Warning at cmake/OpusPackageVersion.cmake:61 (message):
    Could not get package version.
  Call Stack (most recent call first):
    CMakeLists.txt:5 (get_package_version)


  CMake Error at /usr/share/cmake/Modules/CMakeDetermineSystem.cmake:152 (message):
    Could not find toolchain file:
    /home/riyan/Android/Sdk/ndk/build/cmake/android.toolchain.cmake
  Call Stack (most recent call first):
    CMakeLists.txt:7 (project)


  CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.

  thread 'main' panicked at /home/riyan/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/cmake-0.1.54/src/lib.rs:1119:5:

  command did not execute successfully, got: exit status: 1

  build script failed, must exit now
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
note: If the build failed due to a missing target, you can run this command:
note: 
note:     rustup target install aarch64-linux-android

Previous to use of opus it compiles very well and works flawlessly with android how can I compile this opus without error and fix it.

本文标签: cmakeCannot compile opus in rust for android platformStack Overflow