Home > Back-end >  Where to put Kotlin files in a new Android project using mostly Kotlin
Where to put Kotlin files in a new Android project using mostly Kotlin

Time:12-07

I am starting a new Android project for a client. The previous projects were all in Java and we decided to make the jump to Kotlin. On the developer.android.com site I read that it's best to place Kotlin files in src/main/kotlin. However, when I create a new activity, it places my files in src/main/java/<package>. Also, when I want to organize my folder structure in src/main/kotlin I run into issues because right-clicking does not give me the option to create subdirectories. Of course, I can do this in Finder but it seems I am fighting the system. Can someone tell me what the best practice is in terms of Kotlin code organization? I had a hard time finding the answer on Google.

CodePudding user response:

Kotlin files are typically placed in the src/main/java directory when using Android Studio. For instance, if you create a new Kotlin project using one of the provided templates on Android Studio (even on the latest version), the initial Kotlin files are created in the src/main/java directory. This may probably change in the future.

IntelliJ IDEA on the other hand places Kotlin files in the src/main/kotlin directory when developing a Kotlin project.

  • Related