Home > database >  Android 9 failed to connect to OData in Fiori APP and Cordova
Android 9 failed to connect to OData in Fiori APP and Cordova

Time:06-06

I'm facing some problems with an app with Fiori and embebed with Cordova. I made the app without any problems. I configured everything, imported the APK and works fine when I simulate it in Android Studio in the versions: 5.1 and 8.1. When I tried to work with android 9.0 it doesn't comunicate properly with the backend (SAP) and the OData refused to connect. Even when I use the same OData url, user and password than in the other versions of android.

My set:

  • Java 1.8.0
  • Android Studio
  • Android SDK (5.1, 8.1, 9.0)
  • NodeJS v16.0.0
  • Apache Cordova 8.1.2

My config.xml

    <?xml version='1.0' encoding='utf-8'?>
<widget id="com.sap.myui5" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>XXXX-XXXXX</name>
    <description>
        Application hybrida para la preparación de pedidos online de XXX, soportada por Apache Cordova y SAPUI5.
    </description>
    <author email="[email protected]" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
        <preference name="android-minSdkVersion" value="22" />
        <preference name="android-targetSdkVersion" value="29" />
        <icon density="ldpi" src="res/android/ldpi.png" />
        <icon density="mdpi" src="res/android/mdpi.png" />
        <icon density="hdpi" src="res/android/hdpi.png" />
        <icon density="xhdpi" src="res/android/xhdpi.png" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <plugin name="cordova-plugin-keyboard" spec="^1.2.0" />
    <plugin name="cordova-android-support-gradle-release" spec="^3.0.1">
        <variable name="ANDROID_SUPPORT_VERSION" value="22. " />
    </plugin>
    <engine name="android" spec="~9.0.0" />
</widget>

Also my package.json:

    {
  "name": "com.sap.myui5",
  "displayName": "MyUi5App",
  "version": "1.0.0",
  "description": "A sample Apache Cordova application that responds to the deviceready event.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "ecosystem:cordova"
  ],
  "author": "Apache Cordova Team",
  "license": "Apache-2.0",
  "devDependencies": {
    "cordova-android": "^9.0.0",
    "cordova-android-support-gradle-release": "^3.0.1",
    "cordova-plugin-android-permissions": "^1.1.3",
    "cordova-plugin-keyboard": "^1.2.0",
    "cordova-plugin-whitelist": "^1.3.5"
  },
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-keyboard": {},
      "cordova-android-support-gradle-release": {
        "ANDROID_SUPPORT_VERSION": "21. "
      },
      "cordova-plugin-android-permissions": {}
    },
    "platforms": [
      "android"
    ]
  },
  "dependencies": {
    "cordova-android": "~9.0.0"
  }
}

I don't know where the error is. I have set the minSdkVersion and targetSdkVersion in the config.xml, also the dependencies for android 9.0. Could be that the android permissions failed in the android version 9?

"cordova-plugin-android-permissions": "^1.1.3"

Thanks for any help.

CodePudding user response:

Finally I found that I had an error shown in the Network traffic (as DGK talk about). The error was:

net::ERR_CLEARTEXT_NOT_PERMITTED

This error is common with the new version of Android because by default, network requests for clear text traffic are restricted. That's why only failed in Android 9 and not for lower versions.

The solution to this issue is to add to the AndroidManifext.xml another parameter:

<manifest ...>
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>
  • Related