You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10下打开Android GitHub项目遇CMAKE与NDK报错求助

Hi there, let's work through this issue step by step since you're new to NDK development—no worries, we'll get your iperf3-android project compiling properly!

Troubleshooting Steps for NDK/CMake Compilation Error on Windows 10

1. Fix the Compiler Mismatch (Critical Mistake)

The core issue here is that you're trying to use MinGW's GCC compiler for Android NDK cross-compilation, which won't work. Android requires the cross-compiler tools included with the NDK, not a Windows-native compiler like MinGW.

Remove these lines from your CMakeLists.txt immediately:

set(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
set(CMAKE_C++_COMPILER C:/MinGW/bin/g++)

Android Gradle already uses the correct toolchain via the android.toolchain.cmake file referenced in your error log—let it handle compiler selection automatically.

2. Resolve the Empty CMakeLists.txt

It sounds like your project has an extra, empty CMakeLists.txt file that's confusing Gradle. Here's how to fix it:

  • Open your module-level build.gradle file (under app/) and verify the externalNativeBuild block points to the correct, non-empty CMakeLists.txt:
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt" // Make sure this points to the file with iperf3 build logic
        }
    }
    
  • Delete the empty CMakeLists.txt file entirely if it's unused—this eliminates any chance of Gradle picking the wrong configuration file.

3. Let Gradle Handle CMake Execution (Don't Run It Manually!)

As an NDK beginner, you don't need to run CMake commands directly in a terminal. Android Studio and Gradle are designed to manage this for you:

  1. Open the project in Android Studio (don't just work with the extracted zip file directly—IDE integration simplifies setup).
  2. Double-check your SDK Manager installs: Ensure you have a stable NDK version (e.g., r25c, newer than the old ndk-bundle), compatible CMake, and LLDB installed.
  3. Sync your project with Gradle: Click the "Sync Project with Gradle Files" button (the elephant icon) in the top toolbar to reload all configurations.

4. Verify the Project's CMake Configuration

If your main CMakeLists.txt is still incomplete (or was corrupted during download), re-download the project to get the original, working configuration. The official iperf3-android CMakeLists should include logic to compile the iperf3 source code—make sure:

  • include_directories points to the iperf3 header files
  • add_library references the correct source files or subdirectories

5. Clean Up Build Cache & Environment

  • Clear old build artifacts: Go to Build > Clean Project, then Build > Rebuild Project to wipe any cached errors from previous attempts.
  • Check your system PATH: Ensure MinGW's bin directory isn't prioritized over your SDK's CMake/NDK paths—this prevents Gradle from accidentally calling the wrong tools.

内容的提问来源于stack exchange,提问作者Kaustubh Bhatter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:11:22