The error messages
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found. HandshakeException: Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED) # Flutter TypeError: Network request failed # React Native
They all mean the same: Android could not build a chain from the server certificate to a root it trusts.
Cause 1: intermediate certificate missing (most common)
The server sends only its own certificate, not the intermediate. Chrome remembers intermediates from other sites or fetches them via the address in the certificate (AIA), so the error doesn’t show in the browser. An app with OkHttp, Retrofit or Flutter fetches nothing and fails.
Check with the SSL check or on the command line:
openssl s_client -connect api.example.com:443 -servername api.example.com -showcerts </dev/null | grep -c "BEGIN CERTIFICATE"
If the result is 1, the chain is missing. The fix is on the server: configure the certificate with its intermediates, i.e. fullchain.pem instead of cert.pem on nginx and Apache. If you don’t have the chain file, the certificate converter completes it automatically. More in unable to get local issuer certificate.
Cause 2: internal CA the app doesn’t know
Since Android 7, apps only trust the built-in system CAs. A CA certificate the user installs under “Encryption & credentials” is used by Chrome, but not by normal apps. For internal servers the app therefore needs its own network security configuration:
<!-- res/xml/network_security_config.xml -->
<network-security-config>
<domain-config>
<domain includeSubdomains="true">internal.example.com</domain>
<trust-anchors>
<certificates src="@raw/corp_ca" />
<certificates src="system" />
</trust-anchors>
</domain-config>
</network-security-config>
<!-- AndroidManifest.xml --> <application android:networkSecurityConfig="@xml/network_security_config" ... >
The CA goes into the app as res/raw/corp_ca.pem (PEM or DER). If you have it as .cer or .p7b, the certificate converter converts it. For testing with tools like mitmproxy there is also <debug-overrides> with src="user", which only applies to debug builds.
Stay away from a TrustManager that accepts everything: it makes every connection vulnerable, and Google Play rejects apps with such code.
Cause 3: root missing on older devices
Older Android versions don’t know newer root certificates and don’t receive them without a system update. Since 2024 this affects, for example, Let's Encrypt on Android before 7.1.1, because the old cross-signed certificate expired. An example with GlobalSign is described in Android 13 does not trust the certificate. The SSL check shows which root your chain ends in.
Less common causes
- Wrong date on the device: a device with the wrong time considers valid certificates expired or not yet valid.
- Proxy or firewall with TLS inspection: in a company network the firewall replaces the certificate with its own. That fails in apps for the same reason as cause 2.
- Wrong name: the app connects to an IP address or a different name than in the certificate. Then the message is usually
Hostname … not verified.
FAQ
Why does it work on some phones and not on others?
Because some devices still have the intermediate cached or know the root, and others don’t. A completely delivered chain makes the result the same on all devices.
Can I bundle the intermediate in the app?
Technically yes, via network_security_config. Fixing the server is better, otherwise the app breaks again at the server’s next certificate change.
Does this affect iOS too?
iOS fetches missing intermediates in many cases, so an incomplete chain shows up less often there. It is still only correct if the server sends it completely.