更新gradle
diff --git a/Makefile b/Makefile
index a5586c3..83637bb 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
apk:
@echo "build app apk!"
- gradlew assembleRelease
+ gradlew app:assembleRelease
@echo "build android sign apk"
java -jar signapk.jar platform.x509.pem platform.pk8 $(APPPATH)/$(BUILDAPK) $(APPPATH)/$(SIGNAPK)
@echo "build upgrade zip"
diff --git a/app/build.gradle b/app/build.gradle
index dc77cf8..d919594 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -53,7 +53,8 @@
dependencies {
// implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+ implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61'
+ implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.3.61'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
@@ -61,18 +62,18 @@
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
// compile 'com.alibaba:fastjson:1.1.70.android'
- compile 'com.google.code.gson:gson:2.8.5'
- compile 'com.nineoldandroids:parent:2.4.0'
- compile 'com.squareup.okhttp3:okhttp:3.10.0'
- compile 'net.java.dev.jna:jna:4.5.0@aar'
- compile 'com.koushikdutta.async:androidasync:2.2.1'
- compile group: 'com.android.support', name: 'recyclerview-v7', version: '28.0.0'
- compile 'org.apache.commons:commons-lang3:3.7'
- compile 'com.android.support:multidex:1.0.3'
- compile 'org.jetbrains.kotlin:kotlin-reflect:1.3.41'
- compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
- compile 'org.apache.httpcomponents:httpcore:4.4.10'
- compile("com.beust:klaxon:0.30") {
+ implementation 'com.google.code.gson:gson:2.8.6'
+ implementation 'com.nineoldandroids:parent:2.4.0'
+ implementation 'com.squareup.okhttp3:okhttp:4.2.2'
+ implementation 'net.java.dev.jna:jna:5.5.0@aar'
+ implementation 'com.koushikdutta.async:androidasync:2.2.1'
+ implementation group: 'com.android.support', name: 'recyclerview-v7', version: '28.0.0'
+ implementation 'org.apache.commons:commons-lang3:3.9'
+ implementation 'com.android.support:multidex:1.0.3'
+ implementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.61'
+ implementation 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
+ implementation 'org.apache.httpcomponents:httpcore:4.4.13'
+ implementation("com.beust:klaxon:0.30") {
exclude group: 'org.jetbrains'
}
compile files('libs/zxinglibsl.jar')
diff --git a/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt b/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt
index 8765a41..008eeaf 100644
--- a/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt
+++ b/app/src/main/java/com/supwisdom/okhttp/NetworkHandler.kt
@@ -2,14 +2,15 @@
import android.text.TextUtils
import okhttp3.*
+import okhttp3.MediaType.Companion.toMediaTypeOrNull
import java.io.IOException
import java.io.UnsupportedEncodingException
-import java.security.SecureRandom
+import java.security.*
import java.security.cert.CertificateException
import java.security.cert.X509Certificate
+import java.util.*
import java.util.concurrent.TimeUnit
import javax.net.ssl.*
-import com.supwisdom.okhttp.ICallBackok as ICallBack1
/**
** create by zzq on 2019/7/24
@@ -33,13 +34,39 @@
private var client: OkHttpClient? = null
private var clientLong: OkHttpClient
- private val JSON = MediaType.parse("application/json; charset=utf-8")
- private val FORM_ENCODE = MediaType.parse("application/x-www-form-urlencoded;charset=utf-8")
+ private val JSON = "application/json; charset=utf-8".toMediaTypeOrNull()
+ private val FORM_ENCODE = "application/x-www-form-urlencoded;charset=utf-8".toMediaTypeOrNull()
private var commTime = 5
private var clientId: String? = null
private var jwt: String? = null
+ private var sslSocketFactory: SSLSocketFactory? = null
+ private var trustManager: X509TrustManager? = null
init {
+ try {
+ val trustManagerFactory =
+ TrustManagerFactory.getInstance(
+ TrustManagerFactory.getDefaultAlgorithm()
+ )
+ trustManagerFactory.init(null as KeyStore?)
+ val trustManagers =
+ trustManagerFactory.trustManagers
+ check(!(trustManagers.size != 1 || trustManagers[0] !is X509TrustManager)) {
+ ("Unexpected default trust managers:"
+ + Arrays.toString(trustManagers))
+ }
+ trustManager = trustManagers[0] as X509TrustManager
+ val sslContext = SSLContext.getInstance("TLS")
+ sslContext.init(null, arrayOf<TrustManager?>(trustManager), null)
+ sslSocketFactory = sslContext.socketFactory
+ } catch (e: NoSuchAlgorithmException) {
+ e.printStackTrace()
+ } catch (e: KeyManagementException) {
+ e.printStackTrace()
+ } catch (e: KeyStoreException) {
+ e.printStackTrace()
+ }
+
client = OkHttpClient()
.newBuilder()
.retryOnConnectionFailure(false)
@@ -47,7 +74,7 @@
.writeTimeout(1, TimeUnit.SECONDS)
.connectTimeout(commTime.toLong(), TimeUnit.SECONDS)
.hostnameVerifier(TrustAllHostnameVerifier())
- .sslSocketFactory(createSSLSocketFactory()!!)
+ .sslSocketFactory(sslSocketFactory!!, trustManager!!)
.build()
clientLong = OkHttpClient()
.newBuilder()
@@ -56,7 +83,7 @@
.writeTimeout(1, TimeUnit.SECONDS)
.connectTimeout(3, TimeUnit.SECONDS)
.hostnameVerifier(TrustAllHostnameVerifier())
- .sslSocketFactory(createSSLSocketFactory())
+ .sslSocketFactory(sslSocketFactory!!, trustManager!!)
.build()
}
@@ -71,7 +98,7 @@
.writeTimeout(1, TimeUnit.SECONDS)
.connectTimeout(commTime.toLong(), TimeUnit.SECONDS)
.hostnameVerifier(TrustAllHostnameVerifier())
- .sslSocketFactory(createSSLSocketFactory())
+ .sslSocketFactory(sslSocketFactory!!, trustManager!!)
.build()
}
}
@@ -88,46 +115,20 @@
}
}
- private class TrustAllCerts : X509TrustManager {
- @Throws(CertificateException::class)
- override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
- }
-
- @Throws(CertificateException::class)
- override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
- }
-
- override fun getAcceptedIssuers(): Array<X509Certificate> {
- return arrayOf<X509Certificate>()
- }
- }
-
private class TrustAllHostnameVerifier : HostnameVerifier {
override fun verify(hostname: String, session: SSLSession): Boolean {
return true
}
}
- private fun createSSLSocketFactory(): SSLSocketFactory? {
- var ssfFactory: SSLSocketFactory? = null
- try {
- val sc = SSLContext.getInstance("TLS")
- sc.init(null, arrayOf<TrustManager>(TrustAllCerts()), SecureRandom())
- ssfFactory = sc.socketFactory
- } catch (e: Exception) {
- }
-
- return ssfFactory
- }
-
private fun addExtentHeader(request: Request.Builder): Request.Builder {
request.addHeader("Accept", "application/json; q=0.5")
.addHeader("Connection", "close")
if (!TextUtils.isEmpty(clientId)) {
- request.addHeader("X-TENANT-ID", clientId)
+ request.addHeader("X-TENANT-ID", clientId!!)
}
if (!TextUtils.isEmpty(jwt)) {
- request.addHeader("Authorization", jwt)
+ request.addHeader("Authorization", jwt!!)
}
return request
}
@@ -148,8 +149,8 @@
override fun onResponse(call: Call, response: Response) {
try {
- val content = response.body()!!.string()
- val resp = TransResp(response.code(), response.message())
+ val content = response.body!!.string()
+ val resp = TransResp(response.code, response.message)
if (response.isSuccessful) {
resp.retjson = content
}
@@ -205,8 +206,8 @@
override fun onResponse(call: Call, response: Response) {
try {
- val content = response.body()!!.string()
- val resp = TransResp(response.code(), response.message())
+ val content = response.body!!.string()
+ val resp = TransResp(response.code, response.message)
if (response.isSuccessful) {
resp.retjson = content
}
@@ -223,8 +224,8 @@
return try {
val response = clientLong.newCall(request).execute()
/*响应主体只能被消耗一次*/
- val content = response.body()!!.string()
- val resp = TransResp(response.code(), response.message())
+ val content = response.body!!.string()
+ val resp = TransResp(response.code, response.message)
if (response.isSuccessful) {
resp.retjson = content
}
@@ -240,8 +241,8 @@
return try {
val response = client!!.newCall(request).execute()
/*响应主体只能被消耗一次*/
- val content = response.body()!!.string()
- val resp = TransResp(response.code(), response.message())
+ val content = response.body!!.string()
+ val resp = TransResp(response.code, response.message)
if (response.isSuccessful) {
resp.retjson = content
}
diff --git a/build.gradle b/build.gradle
index 3b61f16..fd516ef 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,14 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
- ext.kotlin_version = '1.3.31'
+ ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
-
}
dependencies {
- classpath 'com.android.tools.build:gradle:3.4.0'
+ classpath 'com.android.tools.build:gradle:3.4.2'
+ classpath 'me.tatarka:gradle-retrolambda:3.7.0'
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@@ -17,9 +18,12 @@
allprojects {
repositories {
+ maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
+ maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
+ maven { url 'https://maven.google.com' }
google()
jcenter()
-
+ mavenCentral()
}
}