63

I am getting this error while gradle sync. This is react native project. enter image description here

Sudeep Kumar
  • 839
  • 1
  • 7
  • 16
  • Hi @Sudeep, have you found an answer to this? I am stuck on the same point – Kibi Oct 18 '20 at 08:53
  • @Kibi i got this issue after updating the gradle to latest I reverted it to older version, now everything works fine. But it's not a solution – Sudeep Kumar Oct 21 '20 at 13:04

6 Answers6

58

I was able to work around this issue by adding this line to my build.gradle file:

task prepareKotlinBuildScriptModel {

}
esilver
  • 27,713
  • 23
  • 122
  • 168
  • 1
    After I change the Gradle version from 6.1.1 to 6.5. Had to add an empty task to get this working. – Sreeram Sunkara Nov 02 '20 at 21:55
  • 1
    I am not sure why this is required as none of the code in my project has changed. However, I'm happy this fixed it. :-) – AdamHurwitz Jan 24 '21 at 23:50
  • Not working fine as it is causing other errors. – Tushar Gogna Jun 22 '21 at 14:10
  • 8
    No. This is just not right. Not a single line of code should be added to the project in order to fix a build tool's peculiarities! This is a workaround, not a solution. – egelev Sep 02 '21 at 19:02
  • This is a really annoying bug that Android Studio has introduced by forcing everyone to use Kotlin, shame on them. – Suyash Jul 25 '22 at 03:11
27

just add

tasks.register("prepareKotlinBuildScriptModel"){} 

to build.gradle(Module.app) file.

Issa Khodadadi
  • 917
  • 7
  • 19
16

I had to disable Kotlin in the intellij

Open Preferences>Plugin>Disable Kotlin

enter image description here

Jason Kim
  • 18,102
  • 13
  • 66
  • 105
  • 7
    Unbelievable, what a mess. My project has nothing to do with Kotlin at all, yet I'm running into this issue. Disabling the plugin has helped, thank you – Marian Klühspies Oct 22 '21 at 17:56
  • 12
    DON'T DISABLE Kotlin, it will crash your Android Studio. You've been warned. – Stefan Jul 19 '22 at 14:57
  • 4
    Seriously! Doing this will crash android studio and it asks for reinstalling from scratch!!!!!! – Mohamad Ghaith Alzin Sep 25 '22 at 02:36
  • 2
    However, I solved that problem by removing the `disabled_plugins.txt` in `Users/USER_NAME/Library/Application\ Support/Google/AndroidStudio2021.2/disabled_plugins.txt` – Mohamad Ghaith Alzin Sep 25 '22 at 04:17
  • This will crashes the Android Studio. For more information see [this post](https://stackoverflow.com/q/61682609/6576302) – C.F.G Jan 03 '23 at 16:31
7

For anyone who is working with Ionic Framework (V5), I got this simply because I had opened the /app folder in Android Studio by mistake, instead of opening the root platforms/Android/ project.

Opening the correct root folder then showed the project explorer tree in Android studio as:

  • Android
    • app
    • CordovaLib
    • Gradle Scripts

I was then able to generate a signed apk as usual.

Dave
  • 5,283
  • 7
  • 44
  • 66
7

Disabling Kotlin Plugin , will Crash Your Android Studio so dont Disable it. if you did , delete the disableplugins.txt from c:/users/yourusername/appdata/roaming/google/androidversion


This will work and safe to use.

tasks.register("prepareKotlinBuildScriptModel"){}

6

I followed the instructions from "ITachiLab" mentioned in: ":prepareKotlinBuildScriptModel Task fails in a Java project": https://github.com/gradle/gradle/issues/14889

"In my case the problem was that I had a root Gradle project with multiple subprojects included in root's settings.gradle, while simultaneously having one of the subprojects being added to IntelliJ's Gradle projects manually. In other words: if you have a hierarchical Gradle project, make sure that when you open up the Gradle projects panel in IntelliJ, all subprojects are listed as children of the root. I had one subproject dangling, listed as sibling project of the root. I simply right clicked on it and chose "Unlink Gradle Project". IntelliJ automatically adds projects listed in settings.gradle, you don't have to add them manually by right clicking on a build.gradle and choosing "Link Gradle Project" (that's what I did and it was a mistake)."

Basically: In the Gradle View: Right Click on every Gradle Sub-Project (that is not below the root project but instead directly appears on root level) and select "Unlink Gradle Project (Delete)". BUT do not remove the Gradle Root Project (containing the "settings.gradle.kts" file containing the sub-project includes)! AND then click on "Synchronize". AND now all the gradle sub-projects should appear below the root project and the error should disappear.

becke-ch
  • 413
  • 4
  • 8
  • in same linked thread: "Me as well. I fixed it by deleting the unwanted GradleProjectSettings in the gradle.xml file under .idea folder in the root" – Daniel Hári May 23 '23 at 14:14