blob: 523dc99dd151f57dc8cb9788ab84b48c6da014a1 (
plain)
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
|
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.darylteo.gradle:javassist-plugin:0.4.1'
}
}
import com.darylteo.gradle.javassist.tasks.TransformationTask
import com.darylteo.gradle.javassist.transformers.ClassTransformer
import javassist.CtClass
import javassist.CtConstructor
class StaticBlockRemover extends ClassTransformer {
private static final NATIVE_MAP_VIEW = "com.mapbox.mapboxsdk.maps.NativeMapView";
private static
final NATIVE_CONNECTIVITY_LISTENER = "com.mapbox.mapboxsdk.net.NativeConnectivityListener";
private static final OFFLINE_MANAGER = "com.mapbox.mapboxsdk.offline.OfflineManager";
private static final OFFLINE_REGION = "com.mapbox.mapboxsdk.offline.OfflineRegion";
public void applyTransformations(CtClass clazz) throws Exception {
if (shouldFilter(clazz)) {
CtConstructor constructor = clazz.getClassInitializer()
if (constructor != null) {
clazz.removeConstructor(constructor)
}
}
}
public boolean shouldFilter(CtClass clazz) {
return hasAStaticBlock(clazz);
}
private boolean hasAStaticBlock(CtClass clazz) {
String name = clazz.getName();
boolean isNativeMapView = name.equals(NATIVE_MAP_VIEW);
boolean isNativeConnectivityListener = name.equals(NATIVE_CONNECTIVITY_LISTENER);
boolean isOfflineManager = name.equals(OFFLINE_MANAGER);
boolean isOfflineRegion = name.equals(OFFLINE_REGION);
return isNativeMapView || isNativeConnectivityListener || isOfflineManager || isOfflineRegion;
}
}
task removeStatic(type: TransformationTask) {
// TODO Find a better way to get output classes path
String fromToDirPath = buildDir.getAbsolutePath() + "/intermediates/classes/debug"
from fromToDirPath
transformation = new StaticBlockRemover()
into fromToDirPath
}
afterEvaluate {
compileDebugUnitTestSources.dependsOn(removeStatic)
}
|