Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Android-Studio import of simple project fails #1166

Closed
daberni opened this issue Oct 4, 2018 · 10 comments
Closed

Android-Studio import of simple project fails #1166

daberni opened this issue Oct 4, 2018 · 10 comments

Comments

@daberni
Copy link

daberni commented Oct 4, 2018

After creating a new simple Android project and converting it to kotlin-dsl afterwards, an import of this project with Android Studio (or IntelliJ) fails with different errors depending on how it's imported (Gradle, or Android Gradle). I found no way how this can be done without any errors.

Expected Behavior

Importing the project happens without errors and project compiles therefor.

Current Behavior

IntelliJ doesn't recognize the android project and no local.properties file is created with location to the android-sdk
Although I get the message:

Frameworks Detected
Android framework is detected.
Configure

and clicking on Configure results in a dialog saying No Frameworks detected
Android Studio behaves the same when importing with Gradle and not Android Gradle

Android Studio imports the project by creating a new empty build.gradle file without recognizing the existence of the build.gradle.kts and settings file. The project is then not recognized as an android project and build fails again. When deleting the build.gradle file everything works fine again.

Steps to Reproduce (for bugs)

Checkout repo: https://github.com/daberni/gradle-kotlin-dsl-android-failed
Try to import the project with Android Studio (or IntelliJ)

Your Environment

Android Studio 3.2
Intellij 2018.2.4
Kotlin Plugin: 1.3.0-rc-116

@IVIanuu
Copy link

IVIanuu commented Nov 18, 2018

Is there any way to fix this?

@bamboo
Copy link
Member

bamboo commented Nov 20, 2018

After updating the wrapper to Gradle 4.10.2 with ./gradlew wrapper --gradle-version 4.10.2 I was able to import the project as a Gradle project (not an Android Gradle project as that would trigger the build.gradle file bug).

Android Studio 3.2.1
Kotlin plugin version 1.3.0-release-Studio3.2-1
Build #AI-181.5540.7.32.5056338, built on October 8, 2018
JRE: 1.8.0_152-release-1136-b06 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

@daberni
Copy link
Author

daberni commented Nov 21, 2018

@bamboo where do you get the local.properties file from, when you do not perform an Android Gradle import? I guess this will only get created in an Android context (and one cannot check it in into vcs)

At least using gradle-wrapper 4.10.2 didn't change anything for me

@DavidMihola
Copy link

DavidMihola commented Jan 17, 2019

Has there been any progress on this issue? Since I converted one of our projects to the Kotlin DSL none of my co-workers are able to open the project properly. Neither am I when I try to open a fresh clone of the project.

It does work, however, when I make a copy of the whole project folder, so I am assuming that there must be something inside the folder (but not in Git) that makes it work. But I am afraid I don't know where to look - with a quick look at the iml files and the stuff in the .idea folder I did not see any references to Kotlin DSL or kts files... Am I looking in the wrong place?

@DavidMihola
Copy link

@daberni: I think I am able to consistently get this to work (with your example project and with my own project) when I do the following (thanks to this answer to my Stack Overflow Question)

1.) Clone the project
2.) Delete the .idea folder: rm -rf .idea
3.) Open the project in Android Studio

Can you confirm this?

In this case, the only problem is that I want some files in my .idea folder under version control (code style, etc.)...

@rcosteira79
Copy link

I was able to make it work with @DavidMihola’s solution, but I had to recreate the Android app configuration afterwards. Other than that and the lost .idea files, everything is fine.

@mauricio-custodio
Copy link

@DavidMihola worked for me. @rcosteira79 is also right, I had to create the "app" configuration manually.

  1. Click on "Add Configuration..."
    image
  2. Create new Android App configuration
    image
  3. Select "app" on module
    image
  4. OK

@daberni
Copy link
Author

daberni commented Jan 27, 2019

Just started testing it again and all the suggested work arounds didn't work as expected too. Android Studio doesn't recognize the project as "Android" project and then fails when trying to configure the android gradle tasks. Either local.properties isn't created or an empty build.gradle is created.

What is working at the moment is an Import with the latest Canary version (3.5 - didn't try 3.4 right now). Although the import overrides everything in the .idea folder you can reset those changes with git reset and then the project is set up correctly.

It is still not comparable with standard groovy style build.gradle files. A simple "open" in Android Studio is enough there to get everything up and running.

Furthermore it SHOULD not make a difference when there are some files in the .idea. It's quite common to commit code style settings and run configurations along with the source code.

Jedyny added a commit to WTMBerlin/WTMBApp that referenced this issue Feb 7, 2019
This effectively reverts 6fa1abe

Android Studio in the current stable version (3.3) is not able to recognize imported projects that use Gradle Kotlin DSL as Android projects. I am not sure if it is a problem in Android Studio or Kotlin DSL. There is a bug report in the Kotlin DSL repo here:

gradle/kotlin-dsl-samples#1166

Unfortunately none of the workarounds reported above worked for me. The only way to import the project was to:

1) Checkout the latest commit that used the Groovy DSL
2) Import the project in Android Studio
3) Checkout master

This is of course unnaceptable for any potential contributors, therefore for now we are reverting to Groovy DSL. However, we keep the gradle files in the format that allows swift conversion to Kotlin once the problem described above is solved.
Jedyny added a commit to WTMBerlin/WTMBApp that referenced this issue Feb 7, 2019
This effectively reverts 6fa1abe

Android Studio in the current stable version (3.3) is not able to recognize imported projects that use Gradle Kotlin DSL as Android projects. I am not sure if it is a problem in Android Studio or Kotlin DSL. There is a bug report in the Kotlin DSL repo here:

gradle/kotlin-dsl-samples#1166

Unfortunately none of the workarounds reported above worked for me. The only way to import the project was to:

1) Checkout the latest commit that used the Groovy DSL
2) Import the project in Android Studio
3) Checkout master

This is of course unnaceptable for any potential contributors, therefore for now we are reverting to Groovy DSL. However, we keep the gradle files in the format that allows swift conversion to Kotlin once the problem described above is solved.
apiechowicz added a commit to apiechowicz/obd-analyzer that referenced this issue Apr 11, 2019
Due to a bug related to android projects in kotlin-dsl - gradle/kotlin-dsl-samples#1166
apiechowicz added a commit to apiechowicz/obd-analyzer that referenced this issue Apr 11, 2019
Due to a bug related to android projects in kotlin-dsl - gradle/kotlin-dsl-samples#1166
@eskatos
Copy link
Member

eskatos commented Apr 25, 2019

Closing as outdated, the Gradle Kotlin DSL 1.0 shipped with Gradle 5.0. The sample project uses Gradle 4.6.

@eskatos eskatos closed this as completed Apr 25, 2019
@daberni
Copy link
Author

daberni commented Apr 25, 2019

updated the sample project to Gradle 5.1.1, plugins and kotlin to latest version and works now as expected in Android Studio 3.5 Canary 11 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants