Https not working in latest android devices to read a xml file data using cocos2dx 3.17 c++

Https not working in latest android devices to read a xml file data using cocos2dx 3.17 c++

m using cocos2dx 3.17 to build game using c++…i port game on android side and reading mxl file using https …but it is not working .Game stuck on loading while reading data from xml…it works fine with http on older android devices but not latest android devices due to we change our link to https but its not loading data on older devices and stuck on latest android devices. All help is greatly appreciated .
here is the xm file…

The link you posted is broken, missing an “l” at the end.

Anyhow, if the XML works fine over HTTP, then it’s clearly not the XML. It’s to do with HTTPS.

You need to provide the SSL certificate file (in PEM format), and set it in the HttpClient using the setSSLVerification function:


You only need to do this once, before you start using the HttpClient, and this should work on all Android versions.

Note that if you use cocos2d::network::Downloader, then it will fail on Android 8+ if you’re using a self-signed certificate. There is a way to get it working with self-signed certificates, but it involves a fair amount of work, like creating a subclass of SSLSocketFactory in Java, and implementing your own version of the cocos2d::network::Downloader to utilize it.

I think this link may be useful to you

You can add in your AndroidManifest.xml


That doesn’t solve the issue for the OP, since the OP is asking about HTTPS. What that setting does is enable you to use HTTP, which is also something that is not recommended, for many reasons.

1 Like

@R101 Hmm. The setSSLVerification documentation said if it is empty, SSL verification is disabled.. Did you test the XML download on latest Android? I can’t believe a self signed certificate should be the problem, if you don’t use certificates pinning. (Didn’t tested it yet by myself)

@RoyalStormStudio1 Did you see any helpful messages in the logcat, which refers to the XML download?

The main points from the original post are these:
1 - Connection not working over HTTPS
2 - Connection works over HTTP on older android devices but not latest android devices.
3 - HTTPS not loading data on older devices and stuck on latest android devices

The OP didn’t mention any usage of setSSLVerification, so I assumed that a connection attempt was made to a HTTPS server without a valid PEM formatted certificate being set via setSSLVerification, which is why it isn’t responding (the fact that it’s an XML document isn’t relevant).

The side-note I mentioned regarding the cocos2d::network::Downloader is because Android builds use the Java implementation of the downloader, which doesn’t work with setSSLVerification. This isn’t directly related to the issue in this thread though.

I do Android development for several years now and never needed to add any pem file into my projects. And many of the development servers do have self signed certificates. So I don’t believe this will be the problem - but I can create a minimal project and test that. Maybe I’m wrong.

I’m curious how you haven’t had any issues with self-signed root and client certificates? They were working absolutely fine for me until Android 8 or 8.1, when they suddenly stopped working completely. They still worked fine on a Win32 build of the app.

The self-signed root certificate is installed in Android through the custom certificates, and also provided through the Cocos2d-x app as a PEM file, and the server it connects to also has a self-signed certificate that was created from the self-signed CA root certificate. It may well be that some setting is missing from the certificates, since I’m using a custom OpenSSL config file to create them, but something definitely did change with the newer Android releases.