-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathbuild.gradle
218 lines (190 loc) · 8.3 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
215
216
217
218
/*
* Copyright (c) 2014 Mohit Kanwal.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
* software and associated documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*/
import org.gradle.internal.os.OperatingSystem
apply plugin: 'com.android.application'
def BUILD_TOOLS_VERSION = "19.1.0"
android {
compileSdkVersion 19
buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
// Need to disable pre dexing to be able to build properly
// Otherwise we need to add more tasks to the libraries
// This is a small penalty to keep the house in order!
dexOptions {
incremental false
preDexLibraries = false
jumboMode = false
}
enforceUniquePackageName false
buildTypes {
release {
runProguard true
minifyEnabled true
debuggable false
zipAlign true
proguardFiles 'proguard-rules.txt'
signingConfig debug.signingConfig
}
}
}
/**
* Relies on the Bash Script to manipulate the Dexing of the correct classes.
*/
afterEvaluate { project ->
android.applicationVariants.each {
variant ->
String SDK_DIR = System.getenv("ANDROID_HOME")
if (SDK_DIR == null) {
Properties props = new Properties()
props.load(new FileInputStream(project.rootProject.file("local.properties")))
SDK_DIR = props.get('sdk.dir');
}
String FLAVOR = "${variant.flavorName}"
String BUILD_TYPE = "${variant.buildType.name}"
String ASSET_DIR = "${variant.mergeAssets.outputDir}"
String DEX = "${SDK_DIR}/build-tools/${BUILD_TOOLS_VERSION}/dx"
String BUILD_TOOL_DX = OperatingSystem.current().windows ? "${DEX}.bat" : "${DEX}"
String EX_DIR = "classes"
String LIB_NAME = ""
if ("$FLAVOR" != "")
LIB_NAME = "app-${FLAVOR}-${BUILD_TYPE}"
else
LIB_NAME = "app-${BUILD_TYPE}"
String taskDexSplit = "dex${variant.name.capitalize()}Split"
String taskDexSplit2 = taskDexSplit + "2"
if (variant.buildType.minifyEnabled) {
task("$taskDexSplit") << {
String WORKDIR
if ("$FLAVOR" != "")
WORKDIR = "build/intermediates/classes-proguard/${FLAVOR}/${BUILD_TYPE}"
else
WORKDIR = "build/intermediates/classes-proguard/${BUILD_TYPE}"
task("unzipAndDeleteClassesJar", type: Copy) {
def zipFile = file("${WORKDIR}/classes.jar")
def outputDir = file("${WORKDIR}/${EX_DIR}")
from zipTree(zipFile)
into outputDir
doFirst {
outputDir.deleteDir()
}
doLast {
zipFile.delete()
}
}.execute()
task("extractLibraryClasses", type: Copy) {
String PACKAGE = "com/github/creativepsyco/secondarydex/bigmodule/lib"
def source = file("${WORKDIR}/${EX_DIR}/${PACKAGE}/")
from source
into file("${WORKDIR}/OUTPACKAGE/${PACKAGE}/")
doLast {
source.deleteDir()
}
}.execute()
task("extractGuavaLibrary", type: Copy) {
String PACKAGE = "com/google"
def source = file("${WORKDIR}/${EX_DIR}/${PACKAGE}/")
from source
into file("${WORKDIR}/OUTPACKAGE/${PACKAGE}/")
doLast {
source.deleteDir()
}
}.execute()
task("rebuildClassesJar", type: Exec) {
commandLine "jar", "cvf", "${WORKDIR}/classes.jar", "-C", "${WORKDIR}/${EX_DIR}/", "."
}.execute()
task("dexLibraries", type: Exec) {
commandLine "${BUILD_TOOL_DX}", "--dex", "--output=${ASSET_DIR}", "${WORKDIR}/OUTPACKAGE"
}.execute()
}
if (variant.variantData.obfuscationTask != null) {
println "[Dexing] Adding Task to run after proguard"
tasks.findByName(taskDexSplit).dependsOn variant.variantData.obfuscationTask
} else {
println "[Dexing] Obfuscation task is null ${variant.variantData}"
}
} else {
// For Debug simply remove the library from getting dex and create it
//----------------------- Extra Debug Step ----------------//
def libraryFiles = new ArrayList<?>()
def secondaryFile = new ArrayList<?>()
variant.dex.libraries.each {
File file ->
if (!file.absolutePath.contains("lib${File.separator}unspecified${File.separator}classes.jar")
&& !file.absolutePath.contains("guava")) {
libraryFiles.add(file)
} else {
secondaryFile.add(file)
}
}
variant.dex.libraries = libraryFiles
//----------------------- Extra Debug Step ----------------//
task("$taskDexSplit") << {
def arguments = new ArrayList<?>()
arguments.add("--dex")
arguments.add("--output=${ASSET_DIR}")
arguments.addAll(secondaryFile)
task("dexLibraries", type: Exec) {
executable "${BUILD_TOOL_DX}"
args arguments
// commandLine "${BUILD_TOOL_DX}", "--dex", "--output=${ASSET_DIR}"
// commandLine.addAll(secondaryFile)
}.execute()
}
tasks.findByName(taskDexSplit).dependsOn variant.javaCompile
}
task("$taskDexSplit2") << {
task("zipDexedLibraries", type: Zip) {
destinationDir new File("${ASSET_DIR}")
archiveName 'game.zip'
from "${ASSET_DIR}"
include '*.dex'
doLast {
file("${ASSET_DIR}/classes.dex").delete()
}
}.execute()
task("copyDexedLibrariesToApp", type: Copy) {
from "${ASSET_DIR}/game.zip"
into "build/intermediates/libs/${LIB_NAME}/assets/"
}.execute()
}
/*
tasks.findByName(taskDexSplit).onlyIf(new Spec<Task>() {
boolean isSatisfiedBy(Task task) {
return task.dependsOnTaskDidWork();
}
})
tasks.findByName(taskDexSplit2).onlyIf(new Spec<Task>() {
boolean isSatisfiedBy(Task task) {
return task.dependsOnTaskDidWork();
}
})
*/
// Finally Depend on Dex Task
String dexTaskName = "dex${variant.variantData.name.capitalize()}"
Task dexTask = tasks.findByName(dexTaskName)
dexTask.dependsOn taskDexSplit2
tasks.findByName(taskDexSplit2).dependsOn taskDexSplit
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile project(':lib')
compile 'com.google.guava:guava:18.0'
}