How to import class from another module in android studio?

前端 未结 3 589
孤城傲影
孤城傲影 2020-12-29 01:12

I created two modules in single android project, named it x and y.

  1. Module x has a class Egg (Package: com.example.x)
  2. Module y has a class Foo (Package
相关标签:
3条回答
  • 2020-12-29 01:51

    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
    }
    
    0 讨论(0)
  • 2020-12-29 01:55

    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.

    0 讨论(0)
  • 2020-12-29 02:01

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

        dependencies {
        implementation(
        ...,
        ..,
                project(":y")
    )
    }
    
    0 讨论(0)
提交回复
热议问题