-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathbuild.gradle
214 lines (189 loc) · 7 KB
/
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha01'
classpath 'com.uber:okbuck:0.40.0'
}
}
apply from: rootProject.file('dependencies.gradle')
allprojects {
repositories {
jcenter()
google()
}
}
subprojects { project ->
group = "com.studio"
afterEvaluate {
project.configurations.all {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: 'org.json', module: 'json'
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.javassist', module: 'javassist'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
exclude group: 'com.google.code.findbugs', module: 'annotations'
exclude group: 'org.glassfish', module: 'javax.annotation'
exclude module: 'xmlParserAPIs'
exclude module: 'xpp3'
exclude module: 'xmlpull'
if (it.name.contains("Test")) {
resolutionStrategy {
force 'io.reactivex:rxandroid:1.2.1'
force 'com.android.support:appcompat-v7:24.2.1'
force 'com.android.support:recyclerview-v7:24.2.1'
force 'com.android.support:animated-vector-drawable:24.2.1'
force 'com.android.support:support-v4:24.2.1'
}
}
}
if (project.plugins.hasPlugin('java')) {
addCommonConfigurationForJavaModules(project)
} else if (project.plugins.hasPlugin('com.android.application')
|| project.plugins.hasPlugin('com.android.library')) {
addCommonConfigurationForAndroidModules(project)
}
if (project.plugins.hasPlugin('com.android.application')) {
project.android{
defaultConfig {
multiDexEnabled true
versionCode 1
versionName "1.0.0"
}
signingConfigs {
debug {
storeFile file('config/signing/debug.keystore')
}
}
buildTypes {
release {
signingConfig signingConfigs.debug
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
}
dexOptions {
javaMaxHeapSize "2g"
}
}
}
}
}
def addCommonConfigurationForJavaModules(Project project) {
project.sourceCompatibility = JavaVersion.VERSION_1_8
project.targetCompatibility = JavaVersion.VERSION_1_8
}
def addCommonConfigurationForAndroidModules(Project project) {
project.dependencies {
annotationProcessor 'com.google.auto.service:auto-service:1.0-rc2'
}
project.configurations.all {
exclude module: "log4j-core"
}
project.android {
compileSdkVersion config.build.compileSdkVersion
buildToolsVersion config.build.buildToolsVersion
defaultConfig {
minSdkVersion config.build.minSdkVersion
targetSdkVersion config.build.targetSdkVersion
vectorDrawables.useSupportLibrary = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
abortOnError false
}
}
}
apply plugin: 'com.uber.okbuck'
okbuck {
target = "android-${config.build.compileSdkVersion}"
buildToolVersion = config.build.buildToolsVersion
resourceUnion = false
libraryBuildConfig = false
lint {
disabled = true
}
extraDefs += project.file('DEFS')
buckBinary = "com.github.facebook:buck:2bc390c5c9100a2ff282ee0c53f4346138c747a9@pex"
afterEvaluate {
dependencies {
forcedOkbuck deps.support.values()
forcedOkbuck deps.playServices.values()
forcedOkbuck deps.apt.values()
forcedOkbuck deps.external.gson
forcedOkbuck deps.external.okio
forcedOkbuck deps.external.retrofit
forcedOkbuck deps.external.rxandroid
forcedOkbuck deps.external.rxbinding
forcedOkbuck deps.external.rxjava
forcedOkbuck deps.external.timber
}
}
}
def ENTRIES_TO_DELETE = [
'LICENSE.txt',
'LICENSE',
'NOTICE',
'asm-license.txt',
].join(" ")
def ARCHIVES = [
'.okbuck/cache/org.hamcrest--hamcrest-core--1.3.jar',
'.okbuck/cache/org.hamcrest--hamcrest-library--1.3.jar',
'.okbuck/cache/org.hamcrest--hamcrest-integration--1.3.jar',
'.okbuck/cache/org.mockito--mockito-core--1.10.19.jar',
'.okbuck/cache/org.assertj--assertj-core--1.7.1.jar',
]
gradle.buildFinished {
ARCHIVES.each { archive ->
"zip -d ${archive} ${ENTRIES_TO_DELETE}".execute().waitFor()
}
}
task cleanSources {
doLast {
subprojects.each {
delete fileTree(new File(it.projectDir, "src/")).exclude("main/AndroidManifest.xml")
}
}
}
task addSources {
doLast {
subprojects.each {
if (it.plugins.hasPlugin('com.android.application') || it.plugins.hasPlugin('com.android.library')) {
def sourceFolder = new File(it.projectDir, 'src')
println "Adding sources to: " + sourceFolder
copy {
from fileTree(new File(project.rootDir, "gradle/SourceTemplate/app/src/")).exclude("main/AndroidManifest.xml")
into sourceFolder
}
def activityClass = new File(sourceFolder, "main/java/gradle/example/LoginActivity.java")
def hasAutoService = hasDependency(it, "auto-service")
if (!hasAutoService) {
new File(sourceFolder, "main/java/gradle/example/Service.java").delete()
}
adjustPackage(it, "LoginActivity")
if (hasAutoService) {
adjustPackage(it, "Service")
}
}
}
}
}
boolean hasDependency(Project project, String name) {
project.configurations.getByName("compile").resolve().find { it.name.contains(name) } != null
}
def adjustPackage(Project project, String className) {
def sourceFolder = new File(project.projectDir, 'src')
def sourceFile = new File(sourceFolder, "main/java/gradle/example/${className}.java")
def manifest = new File(sourceFolder, "main/AndroidManifest.xml").text
def projectPackage = manifest.substring(manifest.indexOf('package="') + 9, manifest.indexOf('" xmlns:android'))
def exampleClassFolder = new File(sourceFolder, "main/java/${projectPackage.replace('.', '/')}")
exampleClassFolder.mkdirs()
sourceFile.text = sourceFile.text.replaceAll("package gradle.example;", "package ${projectPackage};")
sourceFile.renameTo(new File(exampleClassFolder, "${className}.java"))
}