简体   繁体   中英

Gradle 3, how to make a library visible to other modules in Android Studio 3?

These are the dependencies of a library module called "mylibrary1" inside project 1

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  api 'com.android.volley:volley:1.0.0'
  ...
}

The keyword api is here to transitively expose this dependency to the consumers of my own library (I'm using Gradle 3). Everything goes fine and the .aar file is made.

Then let's move to another project 2 which is the consumer of the library. I click on file > new module > import .jar/.aar and select the aar file that I made before.

I checked if settings.gradle includes the new module, then a dependency is added to the consumer in this way

api project(':mylibrary1')

Again, the keyword api is necessary to reuse the code from another project that will use the aar of project 2. Anyway, it doesn't change at all even if I put the keyword implementation.

From the classes of project 2 I can see all of my classes in mylibrary1, except those in Volley.

What am I doing wrong? How should I do to solve this problem?

When you package your AAR, it won't include the transitive dependencies, only your own code. So you'll need to add a Volley dependency in your project 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM