1

I am working on an Android native project which builds using CMake. In my build.gradle I specify :

if(project.hasProperty("native")) {
        externalNativeBuild {
            cmake {
                path file('jni/CMakeLists.txt')
                version '3.18.1+'
            }

        }
    }

I want to invoke externalNativeBuild task from command-line only on an automated build server. However I am getting this error:

CMake '3.18.1' or higher was not found in SDK, PATH, or by cmake.dir property.

When I build it inside Android Studio normally, It downloads and install CMake but it is not happening from command-line. Is there a way to do it from command-line?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Vivek Mangal
  • 532
  • 1
  • 8
  • 24

1 Answers1

0

Android studio will automatically create a local.properties file which contains the cmake.dir property.

When you build on the build server, it's more than likely that you your source doesn't have a local.properties file as that file is not normally checked into code repositories. You'll either need to create this file or modify the PATH environment variable to include the cmake binary. This of course presumes that you have CMake installed on the build server. You can do this manually with a .zip/.tarball or if you have access to the SDK on the build server, you can install with the build tools -> How to install Android SDK Build Tools on the command line?

FuriousGeorge
  • 4,561
  • 5
  • 29
  • 52
  • 1
    Shouldn't android gradle plugin automatically install cmake(https://developer.android.com/studio/projects/install-ndk#install_ndk_and_cmake_automatically)? – Vivek Mangal May 14 '22 at 11:36
  • "if their licenses have been accepted in advance". This assumes that you're using plugin 4.2.0+, you've actually accepted the licenses on the server with the appropriate sdkmanager, your build is using said sdkmanager, and that your build server has access to the Internet so that it can pull it in automatically. – FuriousGeorge May 16 '22 at 14:49
  • 1
    It is automatically installing NDK but not cmake. do I need to change anything specific for cmake? – Vivek Mangal May 16 '22 at 15:25
  • Did you accept the licenses for CMake? In a pinch, you can manually install CMake with `yes | ./sdkmanager --install "cmake;"` – FuriousGeorge May 17 '22 at 16:42
  • Is there a way to do it in gradle file instead of doing it on commandline – Vivek Mangal May 18 '22 at 06:16
  • Yes, you can run any arbitrary command in gradle with the `exec` task, but that's just a band aide. – FuriousGeorge May 19 '22 at 13:18
  • https://developer.android.com/studio/intro/update#download-with-gradle – FuriousGeorge Jun 03 '22 at 19:06