-
Notifications
You must be signed in to change notification settings - Fork 1
/
flavors_build.gradle
108 lines (86 loc) · 3.77 KB
/
flavors_build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
apply plugin: 'com.android.application'
// 1. how to keep flavor specific code separate
// 2. how to use code from one flavor to another flavor
// 3. how to add flavor specific dependencies
// Android-Developer link : https://developer.android.com/studio/build/build-variants
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.multiflavorsdemo"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "type"
// we have total 4 flavors here
// - sbq
// - sbx
// - declare
// - full - [combinations of sbq or sbx or declare]
productFlavors {
sbq {
applicationId 'com.example.multiflavorsdemo.sbq'
}
sbx {
applicationId 'com.example.multiflavorsdemo.sbx'
}
declare {
applicationId 'com.example.multiflavorsdemo.declare'
}
full {
applicationId 'com.example.multiflavorsdemo.full'
}
}
// part - 1 : how to keep flavor specific code separate
/* If we want to keep flavor specific code separate we need to create new directory in our src folder with same name as flavor
Eg. here we want to create separate code flavor for sbq, so we will create new new directory in our src folder with name "sbq" */
// part - 2 :how to use code from one flavor to another flavor
/* let say we have a flavor called full which contains combinations of sbq and sbx flavor and we need to share code from sbq and sbx to flavor full
for that we can use 'sourceSets' section where we can define which src can use by which flavor
- By default we need src of main - we include src java-res-assets path to every flavor
- Now we need to share sbq and sbx code to flavor full so we add src-directories of sbq and sbx in flavor full */
sourceSets {
main {
java.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
sbq {
java.srcDirs = ['src/main/java', 'src/sbq/java']
res.srcDirs = ['src/main/res', 'src/sbq/res']
assets.srcDirs = ['src/main/assets', 'src/sbq/assets']
}
sbx {
java.srcDirs = ['src/main/java', 'src/sbx/java']
res.srcDirs = ['src/main/res', 'src/sbx/res']
assets.srcDirs = ['src/main/assets', 'src/sbx/assets']
}
// full flavor src config
full {
java.srcDirs = ['src/main/java', 'src/sbq/java', 'src/sbx/java','src/full/java']
res.srcDirs = ['src/main/res', 'src/sbq/res', 'src/sbx/res','src/full/res']
assets.srcDirs = ['src/main/assets', 'src/sbq/assets','src/sbx/assets', 'src/full/assets']
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':wow')
// part 3 :how to add flavor specific dependencies
// If we want to add dependencies only specific to full flavors we need to add <flavor> + Implementation
fullImplementation 'com.github.bumptech.glide:glide:4.9.0'
}