Răsfoiți Sursa

解决okhttp依赖冲突问题

drake 4 ani în urmă
părinte
comite
4a645a3e35

+ 1 - 1
README.md

@@ -106,7 +106,7 @@ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
 // 支持自动下拉刷新和缺省页的(可选)
 implementation 'com.github.liangjingkanji:BRV:1.3.8'
 
-implementation 'com.github.liangjingkanji:Net:2.2.9'
+implementation 'com.github.liangjingkanji:Net:2.2.10'
 ```
 
 <br>

+ 0 - 1
net/build.gradle

@@ -63,7 +63,6 @@ dependencies {
 
 
     api project(path: ':kalle')
-    implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.12.12'
 
     implementation "com.github.liangjingkanji:Tooltip:1.0.4"
 

+ 0 - 2
net/src/main/java/com/drake/net/NetConfig.kt

@@ -26,7 +26,6 @@ import com.drake.net.NetConfig.host
 import com.drake.net.NetConfig.onDialog
 import com.drake.net.NetConfig.onError
 import com.drake.net.NetConfig.onStateError
-import com.drake.net.connect.OkHttpConnectFactory
 import com.drake.net.error.RequestParamsException
 import com.drake.net.error.ResponseException
 import com.drake.net.error.ServerResponseException
@@ -111,7 +110,6 @@ fun Application.initNet(host: String, config: KalleConfig.Builder.() -> Unit = {
     NetConfig.app = this
     val builder = KalleConfig.newBuilder()
     builder.apply {
-        connectFactory(OkHttpConnectFactory.newBuilder().build())
         network(BroadcastNetwork(this@initNet))
         config()
     }

+ 0 - 127
net/src/main/java/com/drake/net/connect/OkHttpConnectFactory.java

@@ -1,127 +0,0 @@
-/*
- * Copyright (C) 2018 Drake, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.drake.net.connect;
-
-import android.os.Build;
-
-import com.yanzhenjie.kalle.Headers;
-import com.yanzhenjie.kalle.Request;
-import com.yanzhenjie.kalle.RequestMethod;
-import com.yanzhenjie.kalle.connect.ConnectFactory;
-import com.yanzhenjie.kalle.connect.Connection;
-import com.yanzhenjie.kalle.urlconnect.URLConnection;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.Proxy;
-import java.net.URL;
-import java.util.Map;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSocketFactory;
-
-import okhttp3.OkHttpClient;
-import okhttp3.internal.huc.OkHttpURLConnection;
-import okhttp3.internal.huc.OkHttpsURLConnection;
-
-/**
- * Created by Zhenjie Yan on 2016/10/15.
- */
-public class OkHttpConnectFactory implements ConnectFactory {
-
-    public static Builder newBuilder() {
-        return new Builder();
-    }
-
-    private final OkHttpClient mClient;
-
-    private OkHttpConnectFactory(Builder builder) {
-        this.mClient = builder.mClient == null ? new OkHttpClient.Builder().build() : builder.mClient;
-    }
-
-    private HttpURLConnection open(URL url, Proxy proxy) {
-        OkHttpClient newClient = mClient.newBuilder().proxy(proxy).build();
-        String protocol = url.getProtocol();
-        if (protocol.equalsIgnoreCase("http")) return new OkHttpURLConnection(url, newClient);
-        if (protocol.equalsIgnoreCase("https")) return new OkHttpsURLConnection(url, newClient);
-        throw new IllegalArgumentException("Unexpected protocol: " + protocol);
-    }
-
-    @Override
-    public Connection connect(Request request) throws IOException {
-        URL url = new URL(request.url().toString(true));
-        Proxy proxy = request.proxy();
-        HttpURLConnection connection = open(url, proxy);
-
-        connection.setConnectTimeout(request.connectTimeout());
-        connection.setReadTimeout(request.readTimeout());
-        connection.setInstanceFollowRedirects(false);
-
-        if (connection instanceof HttpsURLConnection) {
-            SSLSocketFactory sslSocketFactory = request.sslSocketFactory();
-            if (sslSocketFactory != null)
-                ((HttpsURLConnection) connection).setSSLSocketFactory(sslSocketFactory);
-            HostnameVerifier hostnameVerifier = request.hostnameVerifier();
-            if (hostnameVerifier != null)
-                ((HttpsURLConnection) connection).setHostnameVerifier(hostnameVerifier);
-        }
-
-        RequestMethod method = request.method();
-        connection.setRequestMethod(method.toString());
-        connection.setDoInput(true);
-        boolean isAllowBody = method.allowBody();
-        connection.setDoOutput(isAllowBody);
-
-        Headers headers = request.headers();
-
-        if (isAllowBody) {
-            long contentLength = headers.getContentLength();
-            if (contentLength <= Integer.MAX_VALUE)
-                connection.setFixedLengthStreamingMode((int) contentLength);
-            else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
-                connection.setFixedLengthStreamingMode(contentLength);
-            else connection.setChunkedStreamingMode(256 * 1024);
-        }
-
-        Map<String, String> requestHeaders = Headers.getRequestHeaders(headers);
-        for (Map.Entry<String, String> headerEntry : requestHeaders.entrySet()) {
-            String headKey = headerEntry.getKey();
-            String headValue = headerEntry.getValue();
-            connection.setRequestProperty(headKey, headValue);
-        }
-
-        connection.connect();
-        return new URLConnection(connection);
-    }
-
-    public static class Builder {
-
-        private OkHttpClient mClient;
-
-        private Builder() {
-        }
-
-        public Builder client(OkHttpClient client) {
-            this.mClient = client;
-            return this;
-        }
-
-        public OkHttpConnectFactory build() {
-            return new OkHttpConnectFactory(this);
-        }
-    }
-}