Reputation: 1754
I have some resouces-only Java projects with build.gradle(s):
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
and directory structure:
flavor1/
src/
main/
resources/
assets/
file1.png
flavor2/
src/
main/
resources/
assets/
file1.png
and an another project (this time Android) with build.gradle:
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
productFlavors {
flavor1 {
packageName "com.mydomain.flavor1"
}
flavor2 {
packageName "com.mydomain.flavor2"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
assets.srcDirs = ['assets']
java.srcDirs = ['src/main/java']
}
flavor1 {
res.srcDirs = ['res-flavor1']
assets.srcDirs = ['assets-flavor1']
}
flavor2 {
res.srcDirs = ['res-flavor1']
assets.srcDirs = ['assets-flavor2']
}
}
}
dependencies {
flavor1Compile project(':flavor1')
flavor2Compile project(':flavor2')
}
with directory structure:
android_project/
assets/
assets-flavor1/
assets-flavor2/
res/
res-flavor1/
res-flavor2/
src/
main/
java/
com/
...
The problem is that resources from plain Java projects :flavor1 and :flavor2 are not included into resulting APK. If I include them as global dependencies:
dependencies {
compile project(:flavor1)
}
they are included in the APK fine.
The reason of those plain Java projects is that they are resources both for Android project flavors and other projects (iOS, HTML, Java, that are not described in the question) so I can't include them directly in Android project assets.
Can you please help me?
Upvotes: 2
Views: 2652
Reputation: 28529
Each flavor creates an associated dependency configuration object, so you can do:
dependencies {
flavor1Compile project(':flavor1')
flavor2Compile project(':flavor2')
}
This will package the right assets in the right variant.
Upvotes: 1
Reputation: 10601
Can you add path to Java project resources folder explicitly?
flavor1 {
res.srcDirs = ['res-flavor1']
assets.srcDirs = ['assets-flavor1', '$java-project-root/flavor1/src/main/resources/assets']
}
It is not ideal, but it should work.
Upvotes: 2