TrustKit-Android
TrustKit-Android copied to clipboard
error: cannot find symbol .addInterceptor(OkHttp3Helper.getPinningInterceptor())
Hi there, as the title suggests, it's complaining about not being able to find symbol OkHttp3Helper
and I'm not sure what to do!
package af.myapp;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
import com.zoontek.rnbootsplash.RNBootSplash;
import com.datatheorem.android.trustkit.TrustKit;
import com.datatheorem.android.trustkit.reporting.BackgroundReporter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import okhttp3.OkHttpClient;
// omitted code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Using the default path - res/xml/network_security_config.xml
TrustKit.initializeWithNetworkSecurityConfiguration(this);
URL url = new URL("https://172.30.200.168");
String serverHostname = url.getHost();
// HttpsUrlConnection
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setSSLSocketFactory(TrustKit.getInstance().getSSLSocketFactory(serverHostname));
// OkHttp 3.0.x, 3.1.x and 3.2.x
OkHttpClient client =
new OkHttpClient.Builder()
.sslSocketFactory(OkHttp3Helper.getSSLSocketFactory())
.addInterceptor(OkHttp3Helper.getPinningInterceptor())
.followRedirects(false)
.followSslRedirects(false);
RNBootSplash.init(R.drawable.bootsplash, MainActivity.this); // <- display the generated bootsplash.xml drawable over our MainActivity
}
If you open the project in Android Studio, the linter will show you what class to import.
Also, according to this issue #82 it seems that the code should be added in the MainApplication
file, not MainActivity
It's been a long time, but since I just ran through this issue, here is the solution I found:
The first line of the OkHttp3Helper.java
file exposes the package name (https://github.com/datatheorem/TrustKit-Android/blob/master/trustkit/src/main/java/com/datatheorem/android/trustkit/pinning/OkHttp3Helper.java),
so try adding the following line:
import com.datatheorem.android.trustkit.pinning.OkHttp3Helper;