- Notifications
You must be signed in to change notification settings - Fork 187
Developer API
Quinn edited this page Jul 4, 2022
·
6 revisions
Writing....
Hunter is a framework to develop android gradle plugin based on ASM and Gradle Transform API. You can use Hunter to develop more plugin to monitor your app, enhance 3rd-dependency, enhance android framework.
Plugins based on Hunter support incremental and concurrent compile, so you don't need to afraid of extra build time.
If you want use Hunter to develop a new android gradle plugin, You can use HunterTransform and BaseWeaver,
HunterTransform: It's a incremental and concurrent tool to transport all classes and jars to BaseWeaver. It makes plugins more faster.
BaseWeaver: It's a tool to simplify useage of asm. you just need to tell BaseWeaver which class you want to handle, and provide a ClassWriter to weave the bytecode
finalclassOkHttpHunterTransformextendsHunterTransform {
privateProjectproject;
privateOkHttpHunterExtensionokHttpHunterExtension;
publicOkHttpHunterTransform(Projectproject) {
super(project);
this.project = project;
project.getExtensions().create("okHttpHunterExt", OkHttpHunterExtension.class); //Custom Extension, Optionalthis.bytecodeWeaver = newOkHttpWeaver(); // Custom Weaver, Required!
}
@Overridepublicvoidtransform(Contextcontext, Collection<TransformInput> inputs, Collection<TransformInput> referencedInputs, TransformOutputProvideroutputProvider, booleanisIncremental) throwsIOException, TransformException, InterruptedException {
okHttpHunterExtension = (OkHttpHunterExtension) project.getExtensions().getByName("okHttpHunterExt");
super.transform(context, inputs, referencedInputs, outputProvider, isIncremental);
}
@OverrideprotectedRunVariantgetRunVariant() {
returnokHttpHunterExtension.runVariant; //RunVariant, default value is ALWAYS
}
@OverrideprotectedbooleaninDuplcatedClassSafeMode() {
returnokHttpHunterExtension.duplcatedClassSafeMode;
}
}
publicfinalclassOkHttpWeaverextendsBaseWeaver {
@OverrideprotectedClassVisitorwrapClassWriter(ClassWriterclassWriter) {
returnnewOkHttpClassAdapter(classWriter); //Custom ClassWriter
}
}
buildscript {
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'cn.quinn.hunter:hunter-transform:1.2.1'
}
}