@@ -4,9 +4,6 @@ buildscript {
44 }
55 dependencies {
66 classpath ' com.android.tools.build:gradle:2.3.3'
7- classpath ' com.android.tools.build:transform-api:1.5.+'
8- classpath ' org.javassist:javassist:3.21.+'
9- classpath ' commons-io:commons-io:2.4'
107 }
118}
129apply plugin : ' com.android.application'
@@ -57,124 +54,4 @@ dependencies {
5754 compile ' com.daimajia.easing:library:2.0@aar'
5855 compile ' com.daimajia.androidanimations:library:2.3@aar'
5956 compile ' org.xwalk:xwalk_core_library:23.53.589.4'
60- }
61-
62- import com.android.build.api.transform.Context
63- import com.android.build.api.transform.Format
64- import com.android.build.api.transform.QualifiedContent
65- import com.android.build.api.transform.Status
66- import com.android.build.api.transform.Transform
67- import com.android.build.api.transform.TransformException
68- import com.android.build.api.transform.TransformInput
69- import com.android.build.api.transform.TransformOutputProvider
70- import java.util.jar.JarEntry
71- import java.util.jar.JarFile
72- import java.util.jar.JarOutputStream
73- import javassist.ClassPath
74- import javassist.ClassPool
75- import javassist.CtNewMethod
76- import org.apache.commons.io.FileUtils
77- import org.apache.commons.io.IOUtils
78- import org.gradle.api.logging.Logger
79- class PatchXWalkTransform extends Transform {
80- Logger logger = null ;
81-
82- public PatchXWalkTransform (Logger logger ) {
83- this . logger = logger
84- }
85-
86- @Override
87- String getName () {
88- return " PatchXWalk"
89- }
90-
91- @Override
92- Set<QualifiedContent.ContentType > getInputTypes () {
93- return Collections . singleton(QualifiedContent.DefaultContentType . CLASSES )
94- }
95-
96- @Override
97- Set<QualifiedContent.Scope > getScopes () {
98- return Collections . singleton(QualifiedContent.Scope . EXTERNAL_LIBRARIES )
99- }
100-
101- @Override
102- boolean isIncremental () {
103- return true
104- }
105-
106- @Override
107- void transform (Context context ,
108- Collection<TransformInput > inputs ,
109- Collection<TransformInput > referencedInputs ,
110- TransformOutputProvider outputProvider ,
111- boolean isIncremental ) throws IOException , TransformException , InterruptedException {
112- inputs. each {
113- it. jarInputs. each {
114- def jarName = it. name
115- def src = it. getFile()
116- def dest = outputProvider. getContentLocation(jarName, it. contentTypes, it. scopes, Format . JAR );
117- def status = it. getStatus()
118- if (status == Status . REMOVED ) {
119- logger. info(" PatchXWalkLogger: Remove ${ src} " )
120- FileUtils . delete(dest)
121- } else if (! isIncremental || status != Status . NOTCHANGED ) {
122- Boolean isTargetJar = false
123- String manifestFilePath = new File (src. getParent()). getParent()+ File . separator+ " AndroidManifest.xml" ;
124- def manifestFile = new File (manifestFilePath)
125- if (manifestFile. exists()){
126- def lines = IOUtils . readLines(new FileInputStream (manifestFile)," utf-8" )
127- for (line in lines) {
128- if (line. indexOf(" org.xwalk.core" )> -1 ){
129- isTargetJar = true
130- break
131- }
132- }
133- }
134- if (isTargetJar) {
135- logger. info(" PatchXWalkLogger: Patching ${ src} " )
136-
137- // Patch SslUtil.class
138- def pool = new ClassPool ()
139- pool. insertClassPath(" ${ src} " )
140- def ctc = pool. get(' org.xwalk.core.internal.SslUtil' )
141- logger. info(" PatchXWalkLogger: Replace SslUtil#shouldDenyRequest" )
142- def ctm = ctc. getDeclaredMethod(' shouldDenyRequest' )
143- ctc. removeMethod(ctm)
144- ctc. addMethod(CtNewMethod . make("""
145- public static boolean shouldDenyRequest(int error) {
146- return false;
147- }
148- """ ,
149- ctc))
150- logger. info(" PatchXWalkLogger: Generate bytecode for SslUtil" )
151- def sslUtilBytecode = ctc. toBytecode()
152-
153- // Write back the JAR file
154- def input = new JarFile (src)
155- dest. getParentFile(). mkdirs()
156- def output = new JarOutputStream (new FileOutputStream (dest))
157- input. entries(). each {
158- if (! it. getName(). equals(" org/xwalk/core/internal/SslUtil.class" )) {
159- logger. info(" PatchXWalkLogger: Write back ${ it.getName()} to JAR" )
160- def s = input. getInputStream(it)
161- output. putNextEntry(new JarEntry (it. getName()))
162- IOUtils . copy(s, output)
163- s. close()
164- }
165- }
166- logger. info(" PatchXWalkLogger: Write back modified class to JAR" )
167- output. putNextEntry(new JarEntry (" org/xwalk/core/internal/SslUtil.class" ))
168- output. write(sslUtilBytecode)
169- output. close()
170- } else {
171- logger. info(" PatchXWalkLogger: Copy ${ src} " )
172- FileUtils . copyFile(src, dest)
173- }
174- }
175- }
176- }
177- }
178- }
179-
180- android. registerTransform(new PatchXWalkTransform (logger))
57+ }
0 commit comments