axios: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found (app in react-native)

Describe the bug

"axios": "^0.27.2", I am writing an application in react-native. I get an error when making GET requests: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found everything that I managed to Google does not help.

I have already added android:networkSecurityConfig=“@xml/network_security_config in AndroidManifest.xml and created a file xml/network_security_config.xml

<network-security-config xmlns:tools="http://schemas.android.com/tools"
	xmlns:android="http://schemas.android.com/apk/res/android">
	<domain-config>
		<domain includeSubdomains="true">{ip address of domain}</domain>
		<domain includeSubdomains="true">{need domain}</domain>
		<trust-anchors>
			<certificates src="system" />
			<certificates src="user" />
		</trust-anchors>
	</domain-config>
</network-security-config>

But the error does not disappear… What to do?

About this issue

Most upvoted comments

I had the same problem but now I solved it

More context:

  • My mobile application is made by React Native + Expo 43.
  • I compiled a version for iOS and another for Android.
  • The problem just suddenly happened only in the Android (In all the android devices without have made any change in the mobile app or the server)
  • iOS can connect with the API without problem
  • The website can communicate with the API without problem

It seems to be a problem of the library axios (specifically axiosinstance). Its weird because I didn’t change anything in the android app, it just suddenly stopped to work. (in all the android devices at the same time).

And just doing tests I realized that axiosinstance fail by doing the request (with the exception that I already showed you), but in an inexplicable way if the first request pointing to my API that I do in the app is by using axios it works perfectly, and after that axiosinstance is capable to perform any request to my API without fail.

I know it sounds weird, but now my app is working again.

By other Side, just to let you know, I also tested an android app called API Tester v5.6 and it fails connecting to my API giving me the same exception, but it last version API Tester 5.7 (which was released just some days ago) works without problem.

I also tried to connect to my API with ApiClient v2.4.7 and it fails with the same exception.

Again, I don’t understand what is the real problem but definitely is not the certificate. I left the commentary in here, maybe someone can reproduce it and check?

Same problem here. And I don’t know how to solve

Working fine with IOS but in Android sometimes it works.

Same problem here. And I don’t know how to solve

having the same issue when using ‘expo-video-player’