'Android: Can't import class from another module
I have an Android app module, an Android library module :foo, and a pure java module :bar. In :foo, I have a Foo class, and in :bar, I have a Bar class.
I would like to reference Foo from my Bar class. When I hover over the Foo variable, Android Studio gives me the following suggestion:
Add dependency on module 'MyApplication.foo.main'
When I do as Android Studio suggests, it adds a dependency in build.gradle for the :bar module. After adding the suggested code, this is what my build.gradle looks like:
build.gradle (:bar)
plugins {
id 'java-library'
}
java {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dependencies {
implementation project(path: ':foo')
}
Except there's one small problem; Foo still can't be resolved! Does anyone know how I can import it?
Here is what my project structure looks like:
Solution 1:[1]
So it turns out you cannot add an Android module as a dependency to a pure java module, which I guess makes sense.
Android Studio IDE was just suggesting something that cannot be done, which is misleading.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kc_dev |


