Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.security.cert.CertPathValidatorException: Trust anchor for certification path not found in React-Native [duplicate]

I am building an app in react-native and using axios package for post request. I get the error when axios post request in react-native android app. SSL certificate is signed with letsencrypt.

Https request is working with React-Native 0.47.2 but after upgrading to React-Native 0.55.0 it gives the certificate error.

Certificate is working in both desktop and mobile browsers as well as on application web portal but not working in android app.

Versions android: 8.0.0 React Native: 0.55.0

Error

"java.security.cert.CertPathValidatorException: Trust anchor for certification path not found."

like image 260
zainhassan Avatar asked Nov 08 '22 02:11

zainhassan


1 Answers

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">10.0.2.2</domain><!-- Debug port -->
        <domain includeSubdomains="true">abc.online</domain>
        <trust-anchors>
            <certificates src="@raw/abc"/>
        </trust-anchors>
    </domain-config>
</network-security-config>

This works for me, 10.0.2.2 is the default number for the emulator to communicate with localhost on your machine. If you are using your phone, it should be another IP address.

enter image description here

like image 82
Ming Li Avatar answered Nov 15 '22 04:11

Ming Li