I have two modules in android studio
The domain module in been added to both settings.gradle
and build.gradle
include ':mobile', ':domain'
&
compile project(':domain')
respectively like this
Inside domain module I have a class like this :
public class DomainUtils {
Context mContex;
public DomainUtils(Context context){
this.mContex = context;
}
public void toast(String string){
Toast.makeText(mContex, string,Toast.LENGTH_LONG).show();
}
public String returnHi(){
return "hi";
}
}
But when i try to call new DomainUtils(context).toast("hi");
from a class inside App module :
------------BUT ----------
When I run the method returnHi()
It works fine .
First inside Main Project Folder's settings.gradle
mention the library
include ':app', ':domain'
And include versions if available as well , like
include ':app', ':library-2.19.0'
Now inside app
folder under path MainProject>app>build.gradle
include
dependencies {
..........
compile project(':domain')
}
Again include version details if available. Check out this for more details
Based on the comments, you can do one more verification if library is properly included or not. Clean and rebuild should configure properly, but still just make sure the following is updated by Android Studio .
Check in app.iml
if the module has got included or not
MainProject > app > app.iml
There should be an entry in <component>
tag like below
<orderEntry type="module" module-name="domain" exported="" />
Edit :
Try to run your Toast
message inside runOnUiThread
. It should solve the error.