Skip to content
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

Failed to build on macOS m1 for android #226

Open
thewh1teagle opened this issue Dec 8, 2024 · 0 comments
Open

Failed to build on macOS m1 for android #226

thewh1teagle opened this issue Dec 8, 2024 · 0 comments

Comments

@thewh1teagle
Copy link

thewh1teagle commented Dec 8, 2024

I'm trying to build the crate aec-rs which uses cmake-rs (build.rs) with CMake.

export NDK_HOME="$HOME/Library/Android/sdk/ndk/$(ls -1 $HOME/Library/Android/sdk/ndk | sort | tail -n 1)"
export CMAKE_TOOLCHAIN_FILE="$NDK_HOME/build/cmake/android.toolchain.cmake"
export ANDROID_ABI="arm64-v8a"
cargo ndk -t arm64-v8a -o ./jniLibs build --release

But it failed with:

 -- The CXX compiler identification is Clang 18.0.1
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - failed
  -- Check for working C compiler: /Users/user/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang
  -- Check for working C compiler: /Users/user/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang - broken
  -- Configuring incomplete, errors occurred!

  --- stderr
  CMake Error at /Applications/CMake.app/Contents/share/cmake-3.30/Modules/CMakeTestCCompiler.cmake:67 (message):
    The C compiler

      "/Users/user/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang"

    is not able to compile a simple test program.

    It fails with the following output:

      Change Dir: '/Volumes/Internal/audio/aec-rs/target/aarch64-linux-android/release/build/aec-rs-sys-5aa0159efa82a17d/out/build/CMakeFiles/CMakeScratch/TryCompile-zIjAIO'

I can build clean rust project in the same way.
also, If I add the following in build.rs it compile successfully:

config.define(
    "CMAKE_TOOLCHAIN_FILE",
    "/Users/user/Library/Android/sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake",
);
config.define("ANDROID_ABI", "arm64-v8a");
config.define("ANDROID_PLATFORM", "android-35");
config.define("CMAKE_C_COMPILER", "/Users/user/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android35-clang");
config.define("CMAKE_CXX_COMPILER", "/Users/user/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android35-clang++");

Or the following:

config.define(
        "CMAKE_TOOLCHAIN_FILE",
        "/Users/user/Library/Android/sdk/ndk/27.0.12077973/build/cmake/android.toolchain.cmake",
    );
    config.define("ANDROID_ABI", "arm64-v8a");
    config.define("ANDROID_PLATFORM", "android-35");

However I believe it should pick them automatically from cargo-ndk?

By the way, it also failed with wasm

Update:

// Must set when compile for Android
    // Variables comes from cargo-ndk
    if let Ok(abi) = env::var("CARGO_NDK_ANDROID_TARGET") {
        config.define("ANDROID_ABI", abi);
    }
    if let Ok(platform) = env::var("ANDROID_PLATFORM") {
        config.define("ANDROID_PLATFORM", platform);
    }

Along with

export NDK_HOME="$HOME/Library/Android/sdk/ndk/$(ls -1 $HOME/Library/Android/sdk/ndk | sort | tail -n 1)"
export CMAKE_TOOLCHAIN_FILE="$NDK_HOME/build/cmake/android.toolchain.cmake"
cargo ndk -t arm64-v8a -o ./jniLibs build --release -p libaec

This fix the issue. should I create PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant