Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio cannot open Android project with Kotlin DSL

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?

like image 563
david.mihola Avatar asked Jan 16 '19 11:01

david.mihola


2 Answers

@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.

like image 185
Peike Avatar answered Oct 27 '22 00:10

Peike


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.

like image 31
Boni2k Avatar answered Oct 26 '22 23:10

Boni2k