How to fix build gradle

It helps me with Android Studio.

Delete .gradle dir in your project: rm -rf .gradle


I encountered this same error in a React Native project I am working on. I was able to resolve the issue through the following. Be sure to replace <PROJECT_NAME> below with your actual project name.

  1. Within Android Studio, select File > Invalid Cache and Restart.
  2. Open your project directory in your terminal.
  3. rm -rf .gradle
  4. rm -rf android/.gradle android/.idea
  5. rm android/app/app.iml android/<PROJECT_NAME>.iml

After doing this, I was able to open my project in Android Studio and successfully build. I had tried all but step 3 a few times without success, so my belief is that step 3 and the top-level .gradle directory in my project was the primary issue. I'm not sure how it got there.

One additional note, React Native projects place all of the Android-specific code inside an android directory. So, if your project is not a React Native project, and instead a traditional Android project, the paths I outlined for removal may be different (i.e. they wouldn't be underneath android/).

Tags:

Build

Android