9

I have converted one of our Android projects from the old Groovy settings.gradle and build.gradle files to the new Kotlin DSL, i. e. settings.gradle.kts and build.gradle.kts.

While "it works on my machine" - in particular: the original project I converted from Groovy to Kotlin works fine in its original directory - all my co-workers are unable to open the project when they clone the repo. Importantly, neither can I open the project myself (with the same AS installation on the same machine) when I clone the repo to some other directory. So, I suspect there is some additional detail missing in some configuration file but I cannot seem to figure out which...

Details:

  • When I just use File > Open... and then select the project folder, I only get the error message "The project 'xxx' is not a Gradle-based project"
  • When I instead go through Import Project (Gradle, Eclipse ADT, etc.) and then select Import project from external model and Android Gradle Android Studio will create an empty build.gradle file and fail with the error message "ERROR: Plugin with id 'com.android.library' not found." Deleting the build.gradle just goes back to the error message I described in the first bullet point.

I am aware of this Github issue, which seems to describe the same problem, but it's been very quiet and I thought someone around here must have figured out a solution to this...

Oh, command line builds work everywhere - this is purely an Android Studio problem.

UPDATE: When I copy the whole project to a new folder (instead of cloning the repository) I can open it without any problems. So, am I correct in assuming that there must be something inside the folder - but not in Git - that makes it work?

david.mihola
  • 12,062
  • 8
  • 49
  • 73

2 Answers2

11

I was able to 'fix' it by deleting the .idea directory and reopening the project. The .idea directory is usually not committed in git but I guess copying the directory invalidates the directory structures in the files within the .idea directory.

The whole bug is easily reproducible when you click on File > Re-import Gradle project.

Boni2k
  • 3,255
  • 3
  • 23
  • 27
  • Ah, that's very helpful, thanks! You are right, `File > Re-import Gradle project` breaks even a working project by creating an empty `build.gradle` file - exactly like in my second bullet point. Also, I must admit that I have _some_ files from the `.idea` folder in Git, namely stuff related to the code style... I would have thought this is permissible or even sensible... I can also reproduce your "fix": 1.) clone 2.) `rm -rf .idea` 3.) Open project in AS seems to work consistently... the only problem then is that I lose all my custom configuration in the `.idea` folder... – david.mihola Jan 17 '19 at 12:58
  • Worked perfectly. Just needed to recreate the app configuration though. – Ricardo Costeira Jan 18 '19 at 16:21
  • Since this workaround seems to be the best we can do at the moment, I am marking this as the accepted answer. – david.mihola Jan 21 '19 at 08:48
  • THANK YOU! This also fixes `New Gradle sync not supported due to containing Kotlin modules` issues. – Jeff Jones Sep 04 '19 at 02:20
8

@Boni2k answer does not work for me.

I have to rename the root build.gradle.kts back to build.gradle, fix the syntax error, sync the project (which works fine immediately), and rename the file back to build.gradle.kts. Then the error is gone and I can sync the project successfully.

What I did to raise the error was that I moved the project to a different folder, and rename the project.

Peike
  • 727
  • 4
  • 15