59 lines
2.0 KiB
Groovy
59 lines
2.0 KiB
Groovy
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)
|
|
} |