Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a cpp file in experimental gradle?

Tags:

I'm trying to use Android Studio 1.3.1 to compile an NDK project using the experimental gradle syntax.

My build.gradle looks very much like the one from the Teapot example

With the exception that my source tree has some files which I don't want to include in the build. I can't remove these files so I need gradle to ignore them.

I tried adding an exclude definition:

android.sources {
    main {
        jni {
            source {
                srcDirs 'src/main/jni'

                excludes += "src/main/jni/FileToExclude.cpp"
            }
        }

    }
}

but that did not affect the outcome. gradle still tries to compile this file.

I tried excludes, exclude with =, += and with nothing at all but no permutation works.

like image 958
shoosh Avatar asked Sep 01 '15 12:09

shoosh


2 Answers

From what I've found, the correct directive to exclude the file from the build is exclude, not excludes. Check your build.gradle to make sure you didn't make a mistake here (you've used excludes in the provided sample).

Upd: ok, after some research I found this thread on the AOSP issue tracker. The topic starter says the following:

The java/resources components of the sourcesets allow for include/exclude patterns.

We should do this for aidl/rs/jni/assets.

The issue is still open so I suppose this functionality has to be implemented in the Android Gradle plugin or Android Studio or in both of them (and isn't implemented yet). It'll be implemented in Android Studio 1.5, at least this is what the tags are saying.

like image 167
aga Avatar answered Sep 29 '22 19:09

aga


I think you are giving path of the file in wrong manner. It should be:

srcDir 'src/main/jni'

exclude 'FileToExclude.cpp'

You can follow this link. https://discuss.gradle.org/t/how-can-i-exclude-certain-java-files-from-being-compiled/5287/2

Also note that you should use exclude instead of excludes and srcDir instead of srcDirs.

like image 35
atul Avatar answered Sep 29 '22 20:09

atul