Search code examples
androidmacoscmakeswigapple-m1

Could NOT find SWIG in Android Studio on Mac M1 Pro


I have Android project with C++ code and I'm using CMake 3.10, SWIG 4.1 and NDK 20.1.5948944. On Windows it works fine but on Macbook I have troubles.

I have added environmental variables SWIG_EXECUTABLE, SWIG_DIR.

Build error: Could NOT find SWIG (missing: SWIG_EXECUTABLE SWIG_DIR) (Required is at least version "3.0")

P.S. If I remove this from build.gradle project builds but C++ feature doesn't work.

    externalNativeBuild {
        cmake {
            path "${projectDir}/src/main/cpp/CMakeLists.txt"
        }
    }

Solution

  • Find where SWIG is installed:

    brew info swig
    

    Then edit your CMakefiles and set SWIG_EXECUTABLE / SWIG_DIR accordingly:

    set(SWIG_EXECUTABLE "swig")
    set(SWIG_DIR "/usr/local/Cellar/swig/4.1")
    

    There is a FindSWIG CMake module but it probably doesn't work on macOS : https://cmake.org/cmake/help/v3.10/module/FindSWIG.html

    If this is what your project uses, find it, and then set defaults values for those variables just before this line. This way, your project will work on all platforms.