Search code examples
cordovahttpsfetch

cordova, error when fetching HTTPS in signed application


I have an application in Cordova 11.1.0. When I generate the debug APK, it connects to the server via HTTPS without any problem, but when I sign the APK, it doesn't connect. To create the release, I run:

cordova `build android --release' which generates the .abb file. Later, I run:
java -jar bundletool.jar build-apks --mode universal  --bundle=app-release.aab --output=App.apks --ks=app.keystore --ks-pass=pass:XXXXXX --ks-key-alias=XXXX

Then, I decompress the file with the .apks extension and install the APK that is inside.

I don't know if it's a problem with the app signing process or if it's an error with the application itself.

I used another command:

cordova run android --release -- --keystore=xxxxx.keystore --storePassword=xxxxxx --alias=xxxxx --password=xxxxx --packageType=apk

To sign and generate the apk, but I have the same problem.

I change in my config.xml this:

<preference name="android-minSdkVersion" value="29" />
<preference name="AndroidXEnabled" value="true" />
<preference name="SplashMaintainAspectRatio" value="true" />
**<preference name="scheme" value="https" />
<preference name="hostname" value="my.host" />**

**<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config>**```

But the problem is the same.

Solution

  • How I said, I made a mobile application with apache-cordova. This application when run in debug it's work, but when sign the app, the connection with https has refused. The connection in this case are refused because the services are not in the public access only is avalable in internal network.

    I solved the error follow the next steps.

    1. Install in android device the certificates, Go to Security and find the install certifcates options inside the menu, in each devices are different.

    2. In cordova application in config.xml file, put the next preferences under tag platform name="android"

    3. Create in platforms\android\app\src\res\xml the file network_security_config.xml with this content:

       <network-security-config>  
             <base-config>  
                   <trust-anchors>  
                       <!-- Trust preinstalled CAs -->  
                       <certificates src="system" />  
                       <!-- Additionally trust user added CAs -->  
                       <certificates src="user" />  
                  </trust-anchors>  
             </base-config>  
        </network-security-config>
      
    4. In AndroidManifest.xml add in the tag <application .... the tag android:networkSecurityConfig="@xml/network_security_config"

    That's all.