1

I'm building some C++ libraries through Android Studio and I would like not to pollute my source tree with those .externalNativeBuild folders.

Is it possible to specify where they should land much like buildDir for Java binaries?

I tried using that -B argument like that:

   externalNativeBuild
    {
        cmake
        {
            arguments '-DANDROID_PLATFORM=android-14',
                    '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static',
                    '-BC:/Dev/AndroidCMake'
        }
    }

It works to some extent as the specified folder is created and contains some of the build's by-products. However the build is broken and the .externalNativeBuild folder is still created. It contains some files too. So it looks like that folder is specified somewhere else in the tool chain.

Here is the error I'm getting:

Error:Expected json generation to create 'C:\Dev\Android\TestApp\app\.externalNativeBuild\cmake\debug\armeabi-v7a\android_gradle_build.json' but it didn't

That json file landed in the specified -B folder but the toolchain is still expecting it in that other folder.

Slion
  • 2,558
  • 2
  • 23
  • 27
  • 1
    pollute your source tree? meaning your code is versioned using VCS? just add an ignore rule to it, it's the only folder generated for compiling native code, so it's just one rule – ahasbini Sep 13 '17 at 22:14
  • Yes my code is versioned using a VCS called git. Heard of it? Indeed I ended up adding a few entries to .gitignore, but still it's a pity that folder is somewhat hard coded. – Slion Sep 18 '17 at 06:22

1 Answers1

1

I chanced upon the answer to my own question. Apparently you need to use that buildStagingDirectory property. I have yet to test it but I'm fairly confident it will do the trick.

Slion
  • 2,558
  • 2
  • 23
  • 27
  • 1
    Link does not function, always provide an example usage. – Top-Master May 27 '21 at 02:51
  • 1
    At last, found correct link in [another thread](https://stackoverflow.com/a/60492487/8740349) with example!! see [cmake docs](https://developer.android.com/reference/tools/gradle-api/4.1/com/android/build/api/dsl/Cmake) and details. – Top-Master May 27 '21 at 03:30