Kyle Wolff
Kyle Wolff

Reputation: 151

Adding a library as an aar file in gradle not able to implement interfaces

It would be easier for me to show you but the long story short.

  1. Main Application
  2. Created a Library lets call it SECOND
  3. Created a Shopping List Library call it THIRD

When I add my THIRD dependency to my SECOND library when using implementation in the gradle file, I am not able to implement interfaces for some reason. When using api it works just fine.

Also, we are adding this by importing the aar and pom file manually.

Project Level Gradle For SECOND

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "$projectDir/../THIRD" }
    }

}

Only way to actually allow access to the interfaces is to use API api('com.THIRD.@aar')

Upvotes: 0

Views: 482

Answers (1)

hotkey
hotkey

Reputation: 147991

This is quite as expected: declarations from implementation dependencies of a library are not visible during compilation of the library usages and are only available at runtime.

On contrary, api dependencies are visible during compilation of the library usages, too.

You should only use the implementation configuration if you don't want the library users to see the declaration from a dependency, which is certainly not the case if you expect the user to implement an interface from the dependency.

See: Gradle dependency configuration: implementation vs api vs runtimeonly vs compileonly

Upvotes: 1

Related Questions