How to set up and run Cordova/Ionic Application on Android?

To set up Cordova/Ionic application on Android, follow the steps given below after adding Cordova EnableX plugin:  

  • Step 1: Go inside the Cordova project and open Android folder. 

If Android platform is already added, remove Android and add again using the below command: 

ionic cordova platform rm android && ionic cordova platform add android 
  • Step 2: Set the Minimum SDK version and desugaring in gradle.properties file as shown below:
android.useAndroidX=true 
android.enableJetifier=true 
cdvMinSdkVersion=21 
android.enableDexingArtifactTransform.desugaring=false 

  • Step 3. Add the required libraries like webrtc and socket in the project. properties file as shown below: 
cordova.system.library.7=org.webrtc:google-webrtc:1.0.32006 
cordova.system.library.8=io.socket:socket.io-client:1.0.0 

  • Step 4: If you face “merge debug resource failed” error, then add packagingOptions in app-level build.gradle file in Android block. 
Execution failed for task ':app:mergeDebugJavaResource'. 

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade 

   > More than one file was found with OS independent path 'META-INF/DEPENDENCIES'. 
packagingOptions { 
        exclude 'META-INF/DEPENDENCIES' 
        exclude 'META-INF/LICENSE' 
        exclude 'META-INF/LICENSE.txt' 
        exclude 'META-INF/license.txt' 
        exclude 'META-INF/NOTICE' 
        exclude 'META-INF/NOTICE.txt' 
        exclude 'META-INF/notice.txt' 
        exclude 'META-INF/ASL2.0' 
        exclude("META-INF/*.kotlin_module")  
      }