Thanks, @Niroog. Your solution works and I voted up for your answer. But the solution works only for Cordova android version 6.3.0 and greater. In my case, I had two projects:
- Project 1: Cordova android version 6.3.0,
- Project 2: Cordova android version 6.2.3
For Project 1, the solution given by @Niroog above works fine.
But if someone using version 6.2.3, Here is the solution:-
Step 1:
ionic cordova platform rm android
ionic cordova platform add android@6.3.0 // or greater
ionic cordova prepare android
Step 2:
Follow @Niroog's solution above. And build now
ionic cordova build android
If you still face an error follow step 3. Because in my case after upgrading to 6.3.0, "cordova-plugin-push" folder was generated automatically. So I have to repeat the same solution for push.gradle
file too.
Step 3:
In platforms/android/cordova-plugin-push/XXXX-push.gradle
change classpath 'com.android.tools.build:gradle:+'
to the same version found above: classpath 'com.android.tools.build:gradle:2.2.3'
Then ionic cordova build android