forked from tomahawk-player/tomahawk-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
171 lines (151 loc) · 5.23 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
import java.util.regex.Pattern
/*
* Hack that copies our AndroidManifest.xml so we don't touch the original file, when setting the
* versionName
*/
File srcFile = new File(projectDir, "AndroidManifest.xml")
File destFile = new File(buildDir, "AndroidManifest.xml")
getAnt().copy(file: srcFile.getCanonicalPath(), tofile: destFile.getCanonicalPath())
/*
* Gets the version name from the latest Git tag
*/
def getNewVersionName = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags'
standardOutput = stdout
}
return stdout.toString().trim()
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.1'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile "com.android.support:appcompat-v7:19.0.0"
compile "com.android.support:support-v4:19.0.0"
compile "se.emilsjolander:stickylistheaders:2.1.3"
compile "ch.acra:acra:4.5.0"
compile "org.codehaus.jackson:jackson-core-asl:1.9.13"
compile "org.codehaus.jackson:jackson-mapper-asl:1.9.13"
compile "com.google.guava:guava:16.0"
compile "com.squareup.picasso:picasso:2.1.1"
compile "com.github.castorflex.verticalviewpager:library:19.0.0"
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/ASL2.0'
}
sourceSets {
main {
// We are using a copy of AndroidManifest.xml, so we don't modify the original file
manifest.srcFile 'build/AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
release {
runProguard true
proguardFile 'proguard-android.txt'
applicationVariants.all { variant ->
def file = variant.outputFile
variant.outputFile = new File((String) file.parent,
file.name.replace(".apk", "-" + getNewVersionName() + ".apk"))
}
}
debug {
zipAlign true
}
}
}
///////////////////////////////////////////////////////////////////////
// Tasks related to setting the correct version number automatically //
///////////////////////////////////////////////////////////////////////
task setVersionName {
def manifestFile = file("build/AndroidManifest.xml")
def pattern = Pattern.compile("versionName=\".*\"")
def manifestText = manifestFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
def versionName = getNewVersionName()
println "VersionName: " + versionName
def manifestContent = matcher.replaceAll("versionName=\"" + versionName + "\"")
manifestFile.write(manifestContent)
}
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn setVersionName }
////////////////////////////////////////////////////
// NDK Support (by https://gist.github.com/pboos) //
////////////////////////////////////////////////////
// Make sure the environment variable $ANDROID_NDK_HOME is set:
// example: ANDROID_NDK_HOME /home/maffen/SDKs/android-ndk-r8e
task copyNativeLibs(type: Copy, dependsOn: 'ndkBuild') {
dependsOn 'ndkBuild'
from(new File('libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(buildDir, 'native-libs'))
}
task ndkBuild(type: Exec) {
commandLine new File((String) System.env.ANDROID_NDK_HOME, 'ndk-build')
}
/*
* Include the file "signingconfig.gradle" (which defines the signingConfig), if it exists
* Example of the contents of such "signingconfig.gradle":
*
* android {
* signingConfigs {
* release {
* storeFile file("key.keystore")
* storePassword "password"
* keyAlias "alias"
* keyPassword "password"
* }
* }
*
* buildTypes {
* release {
* signingConfig signingConfigs.release
* }
* }
* }
*
*/
if (new File("signingconfig.gradle").exists()) {
apply from: "signingconfig.gradle";
}