Android Studio: Exclude resource file under resources sourceSets
Exclude paths aren't currently supported for Android sourceSets. You can track this at bug https://code.google.com/p/android/issues/detail?id=64957
This is happening because Android sourceSets aren't the same as Java sourceSets; they're a custom implementation in the Android plugin, and don't automatically pick up all the features of their cousins. This will need to be specially implemented for Android, and it hasn't been done yet.
How to exclude file from resources using Gradle and Android Studio?
For the sanity of other folks working on your project, I strongly discourage putting templates (input) and auto-generated files (output) in the same directory. You could create your own, independent 'templates' directory to keep it from being included in your build.
Gradle 1.2: Exclude directory under resources sourceSets
Using Gradle 1.1, this works for me:
apply plugin: 'war'
sourceSets {
main {
resources {
exclude '**/test/*'
exclude 'certs/test'
}
}
}
Gradle remove resource files from build
According to the answer to this question, it is not possible to remove Android resources from build, but only JAVA resources.
I am now storing the template files in a separate folder, outside the project and using Mako and an additional python script to move them to the drawable folder in the project generation step.
How to exclude resources from the JAR in Gradle and also run via IntelliJ
Excluding Resources from the JAR with Gradle
Example build.gradle
plugins {
id 'java'
id 'application'
}
// Project specifics
version '1.0-SNAPSHOT'
group 'com.example'
sourceCompatibility = 1.8
project.mainClassName = "core.ExampleApp"
dependencies {
testCompile 'junit:junit:4.12'
}
// Define the project source paths
sourceSets {
main.java {
srcDir 'core/src'
}
test.java {
srcDir 'core/test'
}
}
// Exclude all resources from the jar
jar {
processResources.exclude('*')
}
// Allows the 'test' task to see the directories on the classpath
test {
classpath += files('conf')
classpath += files('res')
}
// Allows the 'run' task to see the directories on the classpath
run {
classpath += files('conf')
classpath += files('res')
}
// Adds the directories to classpath in the start scripts
// They will have '$APP_DIR/lib/' prepended so they need to be copied into 'dist/lib/'
startScripts {
run {
classpath += files('conf')
classpath += files('res')
}
}
// Copy 'conf' and 'res' into the 'dist/lib' directory
distributions {
main {
contents {
from('conf').into("lib/conf")
from('res').into("lib/res")
}
}
}
- Resources are found during
gradle run
- Resources are found during
gradle test
- Built JAR does not contain the resources
- Resources copied into
example.zip/lib/conf
&.../lib/res
- Resource content are added to the classpath in the generated build scripts
- Running tests via IntelliJ UI does work (
right click -> run tests
e.g.)
BUT:
- Running via IntelliJ UI does not work (
right click -> run main()
e.g.)
Resolution:
- The IntelliJ Gradle Plugin allows
right click -> run
andright click -> debug
- The above adds a configuration to IntelliJ run panel as a decent substitute
Related Topics
Splash Screen While Loading a Url in a Webview in Android App
How to Handle Empty Response Body with Retrofit 2
How to Get Preview in Composable Functions That Depend on a View Model
Input Has Different Style on Focus
<Select> Not Working in Phonegap App on Android 2.3.3
A Pre-Populated Database Does Not Work at API 28 Throws "No Such Table" Exception
Failed to Resolve: Recyclerview-V7
Error Building Android Library: Direct Local .Aar File Dependencies Are Not Supported
How to Load Image into Imageview from Url Using Glide V4.0.0Rc1
Java.Lang.Nosuchmethoderror: No Static Method Setonapplywindowinsetslistener
How to Add Network_Security_Config.Xml to Manifest in Expo App Without Ejecting
Android Browser Ignores Responsive Web Design
How to Reduce Latency in Mediacodec Video/Avc Decoding
Android Studio - Cannot Resolve Symbol 'Firebase'