3

I have a module called "Common" as library, this module has few dependencies like: com.badlogicgames.gdx, com.squareup.wire etc. And it works fine, I use them inside of this module.

And I have another module called "Tracking", where in the gradle I have:

dependencies {
  compile project(':Common')
}

And if I try there to import any public class of module "Common", it works fine, but if I try to import any class of library com.badlogicgames.gdxor com.squareup.wire, it says me "Cannot resolve symbol ..." and hightlight it red. And no code autocompleting for such classes.

However the project compiles and starts on the device without errors.

Has somebody any idea? I tried "clean and rebuild" for project, "invalidate cashes and restart" for Android Studio. Nothing helps.

Alexander Tumanin
  • 1,638
  • 2
  • 23
  • 37

2 Answers2

1

in the module common you need to declare those transitive dependencies as api to expose them to other modules:

e.g. common/build.gradle:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    api 'com.squareup.wire'
}

https://jeroenmols.com/blog/2017/06/14/androidstudio3/

Milo Bem
  • 1,033
  • 8
  • 20
0

Solution

Change compile to api

dependencies {
  api project(':Common')
}

Reason

Because compile is deprecated, so it is been treated as implementation. FYI compile and api (new keyword for compile) are same in which all internal modules are visible. But new gradle project having compile keyword are treated as implementation. and in implementation internal modules are not visible to main project.

Suggestion

You should declare dependency in your gradle because it is not good to make leak of internal modules.

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212