forked from facebook/fresco
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
177 lines (149 loc) · 5.98 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
apply plugin: 'com.android.library'
apply plugin: 'maven'
project.group = GROUP
version = VERSION_NAME
apply plugin: 'robolectric'
apply plugin: 'de.undercouch.download'
import de.undercouch.gradle.tasks.download.Download
import com.palominolabs.gradle.task.git.clone.GitCloneTask
dependencies {
compile "com.google.code.findbugs:jsr305:${JSR_305_VERSION}"
compile "com.parse.bolts:bolts-android:${BOLTS_ANDROID_VERSION}"
compile "com.nineoldandroids:library:${NINEOLDANDROID_VERSION}"
compile "com.android.support:support-v4:${SUPPORT_V4_VERSION}"
compile "javax.annotation:javax.annotation-api:${ANNOTATION_API_VERSION}"
compile project(':fbcore')
androidTestCompile "com.google.guava:guava:${GUAVA_VERSION}"
androidTestCompile "junit:junit:${JUNIT_VERSION}"
androidTestCompile "org.mockito:mockito-core:${MOCKITO_CORE_VERSION}"
androidTestCompile("org.robolectric:robolectric:${ROBOLECTRIC_VERSION}") {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
}
apply from: rootProject.file('release.gradle')
def generatedTestSources = "$buildDir/generated-src/test"
// Gradle and Buck need different versions of the test runner.
// For gradle, WithTestDefaultsRunner just is a direct sub-class of RobolectricTestRunner.
task generateTestSources {
doLast {
File file = new File(generatedTestSources)
file.mkdirs();
def generated = new File(generatedTestSources, "WithTestDefaultsRunner.java")
generated.text =
"package com.facebook.testing.robolectric.v2;\n" +
"import org.robolectric.RobolectricTestRunner;\n" +
"import org.junit.runners.model.InitializationError;\n" +
"public class WithTestDefaultsRunner extends RobolectricTestRunner {\n" +
" public WithTestDefaultsRunner(final Class<?> testClass) " +
"throws InitializationError {" +
" super(testClass);" +
" }" +
"}"
}
}
test.dependsOn(generateTestSources)
// We download various C++ open-source dependencies from SourceForge into build/downloads.
// We then copy both downloaded code and our custom makefiles and headers into build/nativemerge.
def downloads = new File("${buildDir}/downloads")
def nativemerge = new File("${buildDir}/nativemerge")
task directories {
downloads.mkdirs()
nativemerge.mkdirs()
}
task downloadFiles(dependsOn: directories, type: Download) {
src ([
'http://downloads.sourceforge.net/project/giflib/giflib-5.1.1.tar.gz',
'http://downloads.sourceforge.net/project/libjpeg-turbo/1.3.1/libjpeg-turbo-1.3.1.tar.gz',
'http://downloads.sourceforge.net/project/libpng/libpng16/older-releases/1.6.10/libpng-1.6.10.tar.gz',
])
onlyIfNewer true
overwrite false
dest downloads
}
task cloneWebp(type: GitCloneTask) {
dir = file("${downloads}/libwebp-0.4.2")
uri = 'https://chromium.googlesource.com/webm/libwebp'
treeish = 'v0.4.2'
outputs.dir dir
}
task unpackGiflib(dependsOn: downloadFiles, type: Copy) {
from tarTree(resources.gzip("${downloadFiles.dest}/giflib-5.1.1.tar.gz"))
into "${downloads}"
}
task unpackLibjpeg(dependsOn: downloadFiles, type: Copy) {
from tarTree(resources.gzip("${downloadFiles.dest}/libjpeg-turbo-1.3.1.tar.gz"))
into "${downloads}"
}
task unpackLibpng(dependsOn: downloadFiles, type: Copy) {
from tarTree(resources.gzip("${downloadFiles.dest}/libpng-1.6.10.tar.gz"))
into "${downloads}"
}
task copyGiflib(dependsOn: unpackGiflib, type: Copy) {
from "${unpackGiflib.destinationDir}/giflib-5.1.1/lib"
from 'src/main/jni/third-party/giflib'
include('*.c', '*.h', '*.mk')
into "${nativemerge}/giflib"
}
task copyLibJpeg(dependsOn: unpackLibjpeg, type: Copy) {
from "${unpackLibjpeg.destinationDir}/libjpeg-turbo-1.3.1"
from 'src/main/jni/third-party/libjpeg-turbo-1.3.x'
include('**/*.c', '**/*.h','**/*.S', '**/*.asm', '**/*.inc', '*.mk')
into "${nativemerge}/libjpeg-turbo-1.3.x"
}
task copyLibpng(dependsOn: unpackLibpng, type: Copy) {
from "${unpackLibpng.destinationDir}/libpng-1.6.10"
from 'src/main/jni/third-party/libpng-1.6.10'
include('**/*.c', '**/*.h', '**/*.S', '*.mk')
into "${nativemerge}/libpng-1.6.10"
}
task copyLibWebp(dependsOn: cloneWebp, type: Copy) {
from cloneWebp.dir
from 'src/main/jni/third-party/libwebp-0.4.2'
include('src/**/*.c', 'src/**/*.h', '*.mk')
into "${nativemerge}/libwebp-0.4.2"
}
def makeNdkTasks(String name) {
task "ndk_build_$name"(type: Exec) {
inputs.file("src/main/jni/$name")
outputs.dir("$buildDir/$name")
commandLine 'ndk-build',
'NDK_APPLICATION_MK=../Application.mk',
'NDK_OUT=' + temporaryDir,
"NDK_LIBS_OUT=$buildDir/$name",
'-C', file("src/main/jni/$name").absolutePath,
'--jobs', '8'
}
task "ndk_clean_$name"(type: Exec) {
commandLine 'ndk-build',
'NDK_APPLICATION_MK=../Application.mk',
'NDK_OUT=' + temporaryDir,
"NDK_LIBS_OUT=$buildDir/$name",
'-C', file("src/main/jni/$name").absolutePath,
'clean'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn "ndk_build_$name"
}
clean.dependsOn "ndk_clean_$name"
}
android {
def ndkLibs = ['gifimage', 'imagepipeline', 'memchunk', 'webpimage']
buildToolsVersion "21.1.2"
compileSdkVersion 21
sourceSets {
main {
jni.srcDirs = []
jniLibs.srcDirs = ndkLibs.collect { "$buildDir/$it" }
}
}
ndkLibs.each { makeNdkTasks it }
ndk_build_gifimage.dependsOn(copyGiflib)
ndk_build_imagepipeline.dependsOn([copyLibJpeg, copyLibpng, copyLibWebp])
ndk_build_webpimage.dependsOn(copyLibWebp)
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts.add('archives', sourcesJar)