This repository has been archived by the owner on Jun 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.gradle
198 lines (177 loc) · 6.84 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
buildDir = "$rootDir/build~"
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.+'
classpath 'com.android.tools.build:transform-api:1.5.+'
classpath 'org.javassist:javassist:3.21.+'
classpath 'commons-io:commons-io:2.4'
}
}
repositories {
maven {
url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
}
}
apply plugin: 'com.android.application'
dependencies {
compile 'org.xwalk:xwalk_core_library:22.+'
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
compileSdkVersion 21
buildToolsVersion "25.0.0"
lintOptions {
disable 'MissingTvBanner', 'GradleDynamicVersion', 'GoogleAppIndexingWarning'
}
// Password signing for release
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
def localProperties = new Properties()
localProperties.load(new FileInputStream(localPropertiesFile))
if (localProperties.getProperty("sign.store.file")) {
signingConfigs {
release {
storeFile file(localProperties.getProperty("sign.store.file"))
keyAlias localProperties.getProperty("sign.key.alias", "dashkiosk")
storePassword localProperties.getProperty("sign.store.password", "")
keyPassword localProperties.getProperty("sign.key.password", "")
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
}
}
// Prompting for passwords if needed. Use "./gradlew -q
// assembleRelease" to not get a mangled output.
gradle.taskGraph.whenReady { taskGraph ->
if (android.hasProperty("signingConfigs") &&
android.signingConfigs.hasProperty("release") &&
taskGraph.hasTask(":assembleRelease")) {
def console = System.console()
def release = android.signingConfigs.release
if (release.storePassword == "") {
release.storePassword = new String(console.readPassword("> Keystore password: "))
}
if (release.keyPassword == "") {
release.keyPassword = new String(console.readPassword("> Key password: "))
}
if (release.keyPassword == "") {
release.keyPassword = release.storePassword;
}
}
}
// Create the wrapper
task wrapper(type: Wrapper) {
gradleVersion = '2.14.1'
}
// Patch
import com.android.build.api.transform.Context
import com.android.build.api.transform.Format
import com.android.build.api.transform.QualifiedContent
import com.android.build.api.transform.Status
import com.android.build.api.transform.Transform
import com.android.build.api.transform.TransformException
import com.android.build.api.transform.TransformInput
import com.android.build.api.transform.TransformOutputProvider
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream
import javassist.ClassPath
import javassist.ClassPool
import javassist.CtNewMethod
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils
import org.gradle.api.logging.Logger
class PatchXWalkTransform extends Transform {
Logger logger = null;
public PatchXWalkTransform(Logger logger) {
this.logger = logger
}
@Override
String getName() {
return "PatchXWalk"
}
@Override
Set<QualifiedContent.ContentType> getInputTypes() {
return Collections.singleton(QualifiedContent.DefaultContentType.CLASSES)
}
@Override
Set<QualifiedContent.Scope> getScopes() {
return Collections.singleton(QualifiedContent.Scope.EXTERNAL_LIBRARIES)
}
@Override
boolean isIncremental() {
return true
}
@Override
void transform(Context context,
Collection<TransformInput> inputs,
Collection<TransformInput> referencedInputs,
TransformOutputProvider outputProvider,
boolean isIncremental) throws IOException, TransformException, InterruptedException {
inputs.each {
it.jarInputs.each {
def jarName = it.name
def src = it.getFile()
def dest = outputProvider.getContentLocation(jarName, it.contentTypes, it.scopes, Format.JAR);
def status = it.getStatus()
if (status == Status.REMOVED) {
logger.info("Remove ${src}")
FileUtils.delete(dest)
} else if (!isIncremental || status != Status.NOTCHANGED) {
if (src.toString() ==~ ".*/org.xwalk/xwalk_core.*/classes.jar") {
logger.info("Patching ${src}")
// Patch SslUtil.class
def pool = new ClassPool()
pool.insertClassPath("${src}")
def ctc = pool.get('org.xwalk.core.internal.SslUtil')
logger.debug("Replace SslUtil#shouldDenyRequest")
def ctm = ctc.getDeclaredMethod('shouldDenyRequest')
ctc.removeMethod(ctm)
ctc.addMethod(CtNewMethod.make("""
public static boolean shouldDenyRequest(int error) {
return false;
}
""",
ctc))
logger.debug("Generate bytecode for SslUtil")
def sslUtilBytecode = ctc.toBytecode()
// Write back the JAR file
def input = new JarFile(src)
def output = new JarOutputStream(new FileOutputStream(dest))
input.entries().each {
if (!it.getName().equals("org/xwalk/core/internal/SslUtil.class")) {
logger.debug("Write back ${it.getName()} to JAR")
def s = input.getInputStream(it)
output.putNextEntry(new JarEntry(it.getName()))
IOUtils.copy(s, output)
s.close()
}
}
logger.debug("Write back modified class to JAR")
output.putNextEntry(new JarEntry("org/xwalk/core/internal/SslUtil.class"))
output.write(sslUtilBytecode)
output.close()
} else {
logger.info("Copy ${src}")
FileUtils.copyFile(src, dest)
}
}
}
}
}
}
android.registerTransform(new PatchXWalkTransform(logger))