Reputation: 1296
I created two modules in single android project, named it x and y.
Now I want to import class Foo in the class Egg, for which I wrote the statement mentioned below in class Egg
Import com.example.y.Foo;
Now, Foo is not recognized by android.
Questions,
Is it possible to import Class from a different module using just import statement?
Do I need to create library of Module y and then import created library into module x?
Or may the solution is something else.
Upvotes: 57
Views: 66071
Reputation: 478
Now when you create new module,the settings.gradle file add automatically this module.After that u should add this line:
dependencies {
implementation(
...,
..,
project(":y")
)
}
Upvotes: 13
Reputation: 2605
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.
Upvotes: 10
Reputation: 13039
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
}
Upvotes: 100