我OkHttp
在我的应用程序中使用并添加OkHttp interceptor
到打印日志。如您所见,我只想OkHttp interceptor
为调试 apk导入而不是为发布。
if (BuildConfig.DEBUG) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(String message) {
Log.i(TAG, message);
}
});
logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);
mOkHttpClient = new OkHttpClient.Builder().addInterceptor(logging).build();
}else {
mOkHttpClient = new OkHttpClient();
}
debugImplementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
但是,当我调用./gradlew assembleRelease
它失败时,我使用了它,因为import import okhttp3.logging.HttpLoggingInterceptor;
有没有办法做到这一点?提前致谢。
仅用于调试的导入库问题对我不起作用。
在你的 gradle 中替换
compile 'library'
为了
compileDebug 'library'
在 Gradle 3.0 中不确定但认为它是 implementationDebug/apiDebug
但是在发布时,代码将无法编译。
如果不冲突,可能可行的解决方案是在“main/java”中创建一个接口,该接口将委派您想要的内容而不是特定于库的,然后创建一个文件夹“debug/java”并创建一个实现接口的文件库,从您的代码中调用它,而不是此调试将特定于风味调试编译。在这里编译为没有错误的发布,您可以在“release/java”中指定一个同名的类,并带有一个空实现(如果这不起作用,您将不得不使用 Class#forName 进行查找,它只能用于调试)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句