有android库模块,在调试版本中,它想在发布版本中使用stetho,bot no。我猜它可能会增加对
debugCompile 'com.facebook.stetho:stetho:1.4.1'
debugCompile 'com.uphyca:stetho_realm:2.0.0'
or using
debugImplementation 'com.facebook.stetho:stetho:1.4.1'. // with latest version
debugImplementation 'com.uphyca:stetho_realm:2.0.0'问题在于代码需要将StethoInterceptor放在哪里
OkHttpClient.Builder()
.addNetworkInterceptor(StethoInterceptor())
.build()它如何在发布版本中编译没有stetho依赖?
发布于 2020-06-29 23:45:31
请在您的application类中调用以下checkAndInitStetho()方法:
public YourApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
checkAndInitStetho();
}
private void checkAndInitStetho() {
//Stetho integration
if (BuildConfig.DEBUG) {
try {
SyncTask.executeAndWait(() -> Stetho.initialize(
Stetho.newInitializerBuilder(YourApplication.this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(YourApplication.this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(YourApplication.this))
.build()));
} catch (Exception e) {
LOGE(LOG_TAG, "Error on checkAndInitStetho()", e);
}
}
}
}此外,在创建OkHttpClient.Builder时,应检查其debug模式是否如下所示:-
if (BuildConfig.DEBUG) {
builder.addNetworkInterceptor(new
StethoInterceptor());
}请浏览application类的link
https://stackoverflow.com/questions/62641381
复制相似问题