-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle
166 lines (145 loc) · 6.52 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
import java.util.regex.Pattern
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// If you have installed 'Android Support Repository' from SDK Manager,
// you can get support-v4 library from repository by enabling this line:
// compile 'com.android.support:support-v4:19.0.+'
// But be careful that 'libs/android-support-v4.jar' should be ignored.
}
// For Eclipse ADT users, we should manage versionCode and versionName
// in AndroidManifest.xml.
// So we get them from AndroidManifest and set to DSL objects.
def getVersionCodeFromManifest() {
def manifestFile = file('AndroidManifest.xml')
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def manifestText = manifestFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
return Integer.parseInt(matcher.group(1))
}
def getVersionNameFromManifest() {
def manifestFile = file('AndroidManifest.xml')
def pattern = Pattern.compile("versionName=\"([^\"]+)\"")
def manifestText = manifestFile.getText()
def matcher = pattern.matcher(manifestText)
matcher.find()
return matcher.group(1)
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main']
resources.srcDirs = ['src/main']
aidl.srcDirs = ['src/main']
renderscript.srcDirs = ['src/main']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
androidTest.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')
staging.setRoot('build-types/staging')
}
defaultConfig {
// Get version information from AndroidManifest.
// Without these configs, DSL objects (versionCode, versionName) will be null.
versionCode getVersionCodeFromManifest()
versionName getVersionNameFromManifest()
}
signingConfigs {
releaseSigningConfig {
// Get credentials from properties files.
// ant-release.properties should contain this:
// key.store=YOUR_PRODUCTION_KEYSTORE_NAME.keystore
// key.alias=YOUR_PRODUCTION_ALIAS
// and you should manage this file with git.
//
// private-release.properties should contain this:
// key.store.password=YOUR_PASSWORD_FOR_KEYSTORE
// key.alias.password=YOUR_PASSWORD_FOR_ALIAS
// and you'd better add this file to .gitignore.
def fileAntProperties = file(".release-credentials/ant-release.properties")
def filePrivateProperties = file(".release-credentials/private-release.properties")
println "Reading signing config from ant properties: ${fileAntProperties.absolutePath}"
println "Reading signing config from private properties: ${fileAntProperties.absolutePath}"
if (fileAntProperties.exists() && filePrivateProperties.exists()) {
Properties propsAnt = new Properties()
propsAnt.load(new FileInputStream(fileAntProperties))
Properties propsPrivate = new Properties()
propsPrivate.load(new FileInputStream(filePrivateProperties))
storeFile file(propsAnt['key.store'])
keyAlias propsAnt['key.alias']
storePassword propsPrivate['key.store.password']
keyPassword propsPrivate['key.alias.password']
}
}
stagingSigningConfig {
def fileAntProperties = file(".release-credentials/ant-staging.properties")
def filePrivateProperties = file(".release-credentials/private-staging.properties")
println "Reading signing config from ant properties: ${fileAntProperties.absolutePath}"
println "Reading signing config from private properties: ${fileAntProperties.absolutePath}"
if (fileAntProperties.exists() && filePrivateProperties.exists()) {
Properties propsAnt = new Properties()
propsAnt.load(new FileInputStream(fileAntProperties))
Properties propsPrivate = new Properties()
propsPrivate.load(new FileInputStream(filePrivateProperties))
storeFile file(propsAnt['key.store'])
keyAlias propsAnt['key.alias']
storePassword propsPrivate['key.store.password']
keyPassword propsPrivate['key.alias.password']
}
}
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
buildTypes {
debug {
zipAlign true
}
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile file('proguard-project.txt')
signingConfig signingConfigs.releaseSigningConfig
}
staging {
initWith release
packageNameSuffix ".staging"
signingConfig signingConfigs.stagingSigningConfig
}
}
// Get last commit hash to attach to APK file name.
project.ext.gitHash = "git rev-parse --short HEAD".execute().text.trim()
applicationVariants.all { variant ->
def apk = variant.packageApplication.outputFile;
def newName = apk.name.replace(".apk", "-${variant.mergedFlavor.versionCode}-${variant.mergedFlavor.versionName}-${project.ext.gitHash}.apk");
// If you want to rename unaligned apk, enable this:
// variant.packageApplication.outputFile = new File(apk.parentFile, newName);
if (variant.zipAlign) {
variant.zipAlign.outputFile = new File(apk.parentFile, newName.replace("-unaligned", ""));
}
}
}