Skip to content

Latest commit

 

History

History
53 lines (35 loc) · 1.47 KB

README_hunter_okhttp.md

File metadata and controls

53 lines (35 loc) · 1.47 KB

OkHttp-Plugin

中文

Maybe your project have serveral OkhttpClients,you need to add your custom Interceptor/EventListener/Dns to every OkhttpClients one by one. But some OkhttpClients come from 3rd library, and you can't add your custom Interceptor/EventListener/Dns to them. I have filed a issue about this problem to Okhttp team.

OkHttp-Plugin can help you to achieve it, you can set a global Interceptor/EventListener/Dns to your all OkhttpClients.

How to use it

Add some lines to your build.gradle

dependencies {
    implementation 'com.quinn.hunter:hunter-okhttp-library:0.8.5'
}

repositories {
    jcenter()
}

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.quinn.hunter:hunter-okhttp-plugin:0.9.2'
        classpath 'com.quinn.hunter:hunter-transform:0.9.3'
    }
}

apply plugin: 'hunter-okhttp'
    
OkHttpHooker.installEventListenerFactory(CustomGlobalEventListener.FACTORY);
OkHttpHooker.installDns(new CustomGlobalDns());
OkHttpHooker.installInterceptor(new CustomGlobalInterceptor());
        

I recommend you to upgrade your okhttp to 3.11 or above, it almost costs nothing. If you want to use this plugin for okhttp below 3.11, please read this wiki page: wiki for okhttp-below-3.11