Now step by step to solve this error
STEP 1. First Check your Project-level setting at
File>setting>Build,Execution,Deployment>BuildTools>Gradle
And select the option
Use Default gradle Wrapper(recommende)
And uncheck offline work (if the offline work option is checked)
Step 2. Now create the new project to check the gradle version and android plugin version
Step 3. Go File>Project Structure>Project
Step 4.Now copy that all information
Gradle version
plugin version
Android plugin repository,
Default plugin Repository
STEP 5. Now open the Previous android project where the gradle error occur
STEP 6.Go File> Project Structure> Project> and change the
Gradle version
plugin version
Android plugin repository
Default plugin Repository
Step 7.Sync the gradle now
Step 8 now change the TragetSdkVersion and ComplileSdkVersion
Step 9 .change the dependencies