Skip to content

Commit ccd1f25

Browse files
authored
add Conscrypt to support sni on older android version (android-async-http#1338)
1 parent f387564 commit ccd1f25

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

library/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ android {
2727

2828
dependencies {
2929
api 'cz.msebera.android:httpclient:4.5.8'
30+
compileOnly 'org.conscrypt:conscrypt-android:2.4.0'
3031
}
3132

3233
project.afterEvaluate { project ->

library/src/main/java/com/loopj/android/http/AsyncHttpClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,12 @@ public void cancelRequestsByTAG(Object TAG, boolean mayInterruptIfRunning) {
531531
}
532532
}
533533
}
534+
535+
/**
536+
* Call this method if your app target android below 4.4
537+
* This method enable sni in android below 4.4
538+
*/
539+
public void useConscrypt(){
540+
new ConscryptSSL().install();
541+
}
534542
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.loopj.android.http;
2+
3+
import android.util.Log;
4+
5+
import org.conscrypt.Conscrypt;
6+
7+
import java.security.Security;
8+
9+
public class ConscryptSSL {
10+
11+
public void install(){
12+
try {
13+
Security.insertProviderAt(Conscrypt.newProvider(),1);
14+
}catch (NoClassDefFoundError ex){
15+
Log.e(AsyncHttpClient.LOG_TAG, "java.lang.NoClassDefFoundError: org.conscrypt.Conscrypt, Please add org.conscrypt.Conscrypt to your dependency");
16+
}
17+
18+
}
19+
}

0 commit comments

Comments
 (0)