-
Notifications
You must be signed in to change notification settings - Fork 26
/
build.gradle
148 lines (130 loc) · 4.42 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
import com.android.builder.core.DefaultManifestParser
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
// Set encoding
tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
// 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')
}
// Exclude unneeded files
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
// Remove warnings
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
}
// productFlavors
productFlavors {
def path="./channel.txt"
file(path).eachLine { line->
def words = line.split(':')
def key = words[0]
def channel = words[1]
if (key == '') {
key = channel
}
def name = 's'+channel
"$name" {
manifestPlaceholders=[APP_KEY_PLACEHOLDER:key, APP_PID_PLACEHOLDER:name]
}
}
}
signingConfigs {
release
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), \
'proguard-rules.txt'
}
}
}
// signing
def propFile = file('./signing.properties')
if( propFile.canRead() ) {
def Properties p = new Properties()
p.load(new FileInputStream(propFile))
if( p!=null
&& p.containsKey('STORE_FILE')
&& p.containsKey('STORE_PASSWORD')
&& p.containsKey('KEY_ALIAS')
&& p.containsKey('KEY_PASSWORD')
) {
println "RELEASE_BUILD: Signing..."
android.signingConfigs.release.storeFile = file( p['STORE_FILE'] )
android.signingConfigs.release.storePassword = p['STORE_PASSWORD']
android.signingConfigs.release.keyAlias = p['KEY_ALIAS']
android.signingConfigs.release.keyPassword = p['KEY_PASSWORD']
} else {
println "RELEASE_BUILD: Required properties in signing.properties are missing"
android.buildTypes.release.signingConfig = null
}
} else {
println "RELEASE_BUILD: signing.properties not found"
android.buildTypes.release.signingProperties = null
}
android.applicationVariants.all{ variant ->
// custom package name
def apk = variant.outputs[0].outputFile;
// def versionName = android.defaultConfig.versionName;
def manifestParser = new DefaultManifestParser()
def versionName =manifestParser.getVersionName(android.sourceSets.main.manifest.srcFile)
def newName = "";
if (variant.buildType.name == "release") {
newName = apk.name.replace(".apk", "_V" + versionName + "_release.apk");
} else {
newName = apk.name.replace(".apk", "_V" + versionName + "_debug.apk");
}
newName = newName.replace("-" + variant.buildType.name, "");
variant.outputs[0].outputFile = new File(apk.parentFile, newName);
if (variant.outputs[0].zipAlign) {
variant.outputs[0].zipAlign.outputFile = new File(apk.parentFile, newName.replace("-unaligned", ""));
}
}