How to import class from another module in android studio?

Make sure of the following:

In settings.gradle, you should have: include ':x', ':y'.

In x/build.gradle, you should add y as a dependency:

dependencies {
        compile project(':y')
        // other dependencies
}

now when create new module,settings.gradle add automatically this module.after that u should add this line:

    dependencies {
    implementation(
    ...,
    ..,
            project(":y")
)
}

Combining and correcting two previous answers the best solution is to add this single line to x/build.gradle -> dependencies

implementation project(':y')

compile project() - is deprecated and won't work anymore

If you want to implement just a single module there is no need to use implementation(..., .., project(":y") structure.