1

When using CMake in a regular project, some variables (e.g library paths) can be configured via -D option or by using ccmake or cmake-gui The values are saved in the cache, and this provides for a local configuration that is specific to every user/developer of the code.

In Android Studio, CMake can be configured from Gradle, but I haven't been able to find an equivalent to the options above. The local.properties file can be read from gradle, but it's overwritten by AS.

Is there any way of setting CMake variables to local values from Android Studio?

Example: On a regular CMake project, I can add a line to my CMakeLists.txt like:

set(EIGEN_DIR /usr/local/include/eigen3 CACHE PATH "Eigen path")

And then two different developers may set that value to their particular systems (ie. /usr/local/include/eigen3 or /opt/local/include/eigen3) without affecting the project source code. However, in Android Studio, the only way seems to be from build.gradle, which is part of the project, and will get committed to the repositories.

2
  • developer.android.com/ndk/guides/cmake.htm, use format "-Dyour-cmake-variables=VALUE". this should be saved into build/.externalNativeBuild somewhere there Commented Aug 24, 2017 at 6:10
  • Those variables are not local. I'll add an example of the intended usage to my question Commented Aug 24, 2017 at 6:13

1 Answer 1

2

I found this can be achieved by putting the variables with the desired value in the local.properties file, and then read them with the code from this answer:

Properties props = new Properties() props.load(new FileInputStream(project.rootProject.file('local.properties'))) String conf_value = props['conf.value'] 

and then

externalNativeBuild{ cmake { arguments "-DMY_CONF_VALUE="+conf_value ... } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.