We're making some library, basicly for our API, that we would make life easier for our external developers.
So we created new library project and put Retrofit and some other libraries as dependencies.
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
Now when we build it, it produces aar file.
But now when we put the aar file to libs directory and set it as dependency, we still have to put the same dependency in user's build.gradle file, which sucks. It should be taken from the library, right?
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ourlibrary', ext: 'aar') {
transitive = true;
}
}
How to make transitive = true work?
The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.
It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.
In your case adding transitive=true doesn't resolve your issue for the reason described above.
You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.
Related
We're making some library, basicly for our API, that we would make life easier for our external developers.
So we created new library project and put Retrofit and some other libraries as dependencies.
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
Now when we build it, it produces aar file.
But now when we put the aar file to libs directory and set it as dependency, we still have to put the same dependency in user's build.gradle file, which sucks. It should be taken from the library, right?
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ourlibrary', ext: 'aar') {
transitive = true;
}
}
How to make transitive = true work?
The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.
It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.
In your case adding transitive=true doesn't resolve your issue for the reason described above.
You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.
We're making some library, basicly for our API, that we would make life easier for our external developers.
So we created new library project and put Retrofit and some other libraries as dependencies.
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:retrofit:2.0.1'
compile 'com.squareup.retrofit2:converter-gson:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
Now when we build it, it produces aar file.
But now when we put the aar file to libs directory and set it as dependency, we still have to put the same dependency in user's build.gradle file, which sucks. It should be taken from the library, right?
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name: 'ourlibrary', ext: 'aar') {
transitive = true;
}
}
How to make transitive = true work?
The aar file doesn't contain the nested (or transitive) dependencies and doesn't have a pom file which describes the dependencies used by the library.
It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.
In your case adding transitive=true doesn't resolve your issue for the reason described above.
You should use a maven repository (you have to publish the library in a private or public maven repo), you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.
I'm developing an android library that depends on some third party aars and jars.
Currently, these dependencies are declared in the library module's gradle buildscript like so:
repositories {
flatDir{
dirs 'libs', 'android-libs'
}
}
dependencies{
compile(name: 'threetenabp-1.0.5', ext: 'aar')
compile fileTree(include: ['*.jar'], dir: 'libs')
}
However, this results in the dependencies' classes being built into the aar, potentially causing conflicts when the library is used in an application.
How can I reference these dependencies from my library without actually packaging them into the library?
I have tried changing the declarations from "compile" to "provided" and then compiling the files into the application, but when I do this my library fails to build.
After some reading at https://docs.gradle.org/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies I eventually figured out that using compile fileTree will package the dependencies into the output library. To avoid this, declare each dependency individually, using the following syntax:
dependencies {
compile: name: 'filename-without-extension'
}
And the dependencies will no longer be packaged into the output.
The project making use of the output aar will still need to include the flat-dir repository that holds the jar files, like so:
repositories {
flatDir{
dirs 'libs'
}
}
I have an android library distributed in aar format. It weight 300kb.
I want to create another library and also in aar format, where first library in dependencies.
But result library weight is 30kb, so obviously it does not not include first library.
I tried to add first library using flatDir:
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'mylib-1.0', ext:'aar')
}
And publish to mavenLocal using maven-publish:
repositories {
mavenLocal()
}
dependencies {
compile 'com.mylib:mylib:1.0.0#aar'
}
but still it does not include to result aar.
How to include my first aar to result aar?
The best way to achieve it is to distribute the aar with a maven repo.
The aar file doesn't contain the transitive dependencies and doesn't have a pom file which describes the dependencies used by the library.
It means that, if you are importing a aar file using a flatDir repo you have to specify the dependencies also in your project.
Using a maven repository you will not have the same issue.
In this case, gradle downloads the dependencies using the pom file which will contains the dependencies list.
I'm creating an Android App. All the business logic is in a library that I'm adding to my app project importing its AAR file.
But this library has some compiled project dependencies I'd need to use from the app, but don't know how.
LIBRARY PROJECT
apply plugin: 'com.android.library'
dependencies {
compile 'com.android.support:appcompat-v7:22.1.1'
compile(name: 'lib1', ext: 'jar')
compile project(':lib2')
I'm exporting this library as mobile-release.aar.
APP PROJECT
dependencies {
compile(name:'mobile-release', ext:'aar')
How can I access from my app project to those lib1, lib2 from mobile-release?
I tried adding
compile(:mobile-release:lib1)
without success. Thanks!
the short solution is to include your library aar file as module dependency in the application project, and then add the library dependencies
//in app projet
dependencies {
//....
compile project(':mobile-release') {
dependencies {
compile(name: 'lib1', ext: 'jar')
compile project(':lib2')
}
}
}
there are other solutions like publish you library to a local/remote repository, or create a function in the library gradle file that takes the jar dependencies and add them to the generated aar