Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import class from another module in android studio?

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: com.example.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.

like image 702
Palak Avatar asked Dec 22 '15 16:12

Palak


People also ask

What is Java module in Android Studio?

These modules allow you to store source code and Android resources which can be shared between several other Android projects. To use a Java library (JAR file) inside your Android project, you can simple copy the JAR file into the folder called libs in your application.


1 Answers

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 } 
like image 136
pdegand59 Avatar answered Oct 06 '22 23:10

pdegand59