'Gradle build failed in Ionic 5

i tried running an ionic app on a real android device using capacitor

npx cap run android

I got this error

Running Gradle build - failed!

here is my Gradle file

dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath 'com.google.gms:google-services:4.3.5'
    }
}

apply from: "variables.gradle"

allprojects {
    repositories {
        google()
        jcenter()
    }

this is my ionic info

Capacitor:

   Capacitor CLI      : 3.4.3
   @capacitor/android : 3.4.3
   @capacitor/core    : 3.4.3
   @capacitor/ios     : not installed

Cordova:

   Cordova CLI       : 10.0.0 ([email protected])
   Cordova Platforms : browser 6.0.0, ios broken

System:

   NodeJS : v17.8.0 (/usr/local/Cellar/node/17.8.0/bin/node)
   npm    : 8.6.0
   OS     : macOS Monterey


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source