Native app Network request failed error

0
Hi, Recently we upgrade our Mendix version from 8.6.0 to 8.6.3 and regenerated the android app using native template version 3.2.2 When starting the app, the following error message popups “A connection error occured” message, please try again later” And in the logs it shows the following logline: ReactNativeJS: 'Network request failed', 'construct@[native code]\nc@index.android.bundle:28:482 Important to note is that the server uses a SSL certificate, which is singed by a custom CA, which is imported in the android device. In chrome the mendix homepage loads without any problems, However in the native app it does not seem to accept the connection.    Did anybody experience similar issues?
asked
1 answers
2

In the end I was able to find the solution myself, which I'll share below.

As mentioned in the post the Mendix server used a SSL certificate which is signed by an internal custom CA. 
By default behavior custom/user-added CA's are disabled, unless explicitly allowed via the network security configuration of the APK. See, the documentation below for a more detailed explanation.

“By default, secure connections (using protocols like TLS and HTTPS) from all apps trust the pre-installed system CAs, and apps targeting Android 6.0 (API level 23) and lower also trust the user-added CA store by default.”

https://developer.android.com/training/articles/security-config#CustomTrust

The solution is as follows:

  1. Prepare the project using the native builder to generate a github project (skip if it already exists)
  2. In the github master branch add the file  "app/src/main/res/xml/network_security_config.xml”
       <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
        <base-config cleartextTrafficPermitted="false">
            <trust-anchors>
                <certificates src="system" />
                <certificates src="user" />
            </trust-anchors>
        </base-config>
    </network-security-config>
  3. Add the “networkSecurityConfig” line directly after the application tag in app/src/main/AndroidManifest.xml
    <Application
    	    android:networkSecurityConfig="@xml/network_security_config"
    		...
  4. Now proceed with the native builder command as usual.
    During this step the network_security_config.xml will be included in the apk.
    When installing custom CA/self-signed certificates on the android device, these will be taken into account.
answered