0

To permanently exclude specific file(s) from being compiled in Android Studio, we can add full path of the file(s) to be ignored in the following list:

File -> Other Settings -> Default Settings -> Compiler -> Excludes 

But, how do we permanently exclude arbitrary file(s) from being compiled? I'd like to exclude files with certain keywords (can we use regex for this?) or specific file pattern (e.g. .DS_STORE).

I'm running Android Studio Version 0.4.3.

2 Answers 2

1

If your project uses Gradle, that preference won't work, because Gradle ignores those compiler settings -- we've filed bug https://code.google.com/p/android/issues/detail?id=64825 to track the suppression of preferences panels that don't apply.

To do this in Gradle, you use exclude statements inside your java sourceSet statements. By default new projects created in Android Studio don't specify a sourceSet because they use the implicit src/main/java directory, but you can override it. See http://www.gradle.org/docs/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:sourceSets(groovy.lang.Closure) for information on the exclude keyword and http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Sourcesets-and-Dependencies for information on source sets in the Android Gradle plugin.

Note that this exclude keyword only works for the Java and resource source sets in the current version of the Android Gradle plugin; it's not implemented for other source sets like AIDL or RenderScript or JNI or Assets. See https://code.google.com/p/android/issues/detail?id=64957 to track the progress of that.

Sign up to request clarification or add additional context in comments.

Comments

0

I excludes some files in Android Studio as following.

File (or Android Studio on Mac) -> Preferences -> File Types -> Ignore Files and Folders (at the very bottom) -> put ".DS_Store;.git;*.iml;.idea;"

With this configuration everything build just fine, and there is no unnecessary files and folders in the project tree.

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.