Developer API

Quinn edited this page Jan 6, 2019 · 5 revisions


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

final class OkHttpHunterTransform extends HunterTransform {

    private Project project;
    private OkHttpHunterExtension okHttpHunterExtension;

    public OkHttpHunterTransform(Project project) {
        this.project = project;
        project.getExtensions().create("okHttpHunterExt", OkHttpHunterExtension.class); //Custom Extension, Optional
        this.bytecodeWeaver = new OkHttpWeaver();  // Custom Weaver, Required!

    public void transform(Context context, Collection<TransformInput> inputs, Collection<TransformInput> referencedInputs, TransformOutputProvider outputProvider, boolean isIncremental) throws IOException, TransformException, InterruptedException {
        okHttpHunterExtension = (OkHttpHunterExtension) project.getExtensions().getByName("okHttpHunterExt");
        super.transform(context, inputs, referencedInputs, outputProvider, isIncremental);

    protected RunVariant getRunVariant() {
        return okHttpHunterExtension.runVariant; //RunVariant, default value is ALWAYS

    protected boolean inDuplcatedClassSafeMode() {
        return okHttpHunterExtension.duplcatedClassSafeMode;

public final class OkHttpWeaver extends BaseWeaver {

    protected ClassVisitor wrapClassWriter(ClassWriter classWriter) {
        return new OkHttpClassAdapter(classWriter);  //Custom ClassWriter


buildscript {
    repositories {
    dependencies {
        classpath 'com.quinn.hunter:hunter-transform:0.9.0'
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.