Stack
Stack

Reputation: 1264

Android - Java Package name not changes to Kotlin even though kotlin is used as a language

I am using kotlin as a programming in android application, even though am using kotlin as language my default application package shows as java.

enter image description here

But am not sure that this is the default behaviour, is it possible to change to kotlin ?

Upvotes: 3

Views: 2237

Answers (2)

hardik9850
hardik9850

Reputation: 1106

If you are using kts gradle system, then the code suggested by jeet might not work for you.

You can try with below piece of code in app level build.gradle.kts

android.sourceSets.all {
    java.srcDir("src/$name/kotlin")
}

Upvotes: 2

Jeel Vankhede
Jeel Vankhede

Reputation: 12138

Yes, you can take any name as your package name source. All you'll have to do is just provide that name to sourceSet in Android Studio.

How to do that?

Follow the steps:

  1. Click on java package you want to refactor and then click (shft+F6), popup opens and then rename it to 'kotlin'.
  2. Go to app level build.gradle file and then add code below in android block :

    android {
    ....
        sourceSets{
            main.java.srcDirs += 'src/main/kotlin'
        }
    ....
    }
    

Now, sync the project and you're good to go.

Upvotes: 7

Related Questions