How to include dependencies when publish the library to bintray in android - android

I'm new to publish own library in android.
I created my own library and uploaded it to bintray. My library depends several third party libraries. When I see pom.xml file, there are dependency information.
But when I add my library to test project gradle, it didn't import its dependencies. So I had to add it manually test project's gradle. How can I import dependency module automatically when I add my library to test project's gradle?
Is there anyone that can solve this? My library is on binary's maven repository.
I find expert in this scope now.

You need to include your library as a transitive dependency. Your build.gradle should have something like this:
compile('com.example.your.library:0.1.0#aar') {
transitive = true;
}

Related

Can I include a local module in my published aar library?

I am working on a project with a few modules, something like this:
:app
:coreLib
:exportLibrary
:otherLibrary
in my build.gradle for my exportLibrary module I import coreLib like this:
implementation(project("coreLib"))
and in my app I do the same to include exportLibrary:
implementation(project("exportLibrary"))
What I want to do is publish exportLibrary to a maven repository, and I want it to include everything from coreLib. I haven't found a good way to do this yet. Adding a transitive flag does not help. What am I missing?
I hope I do not need to publish coreLib too!
I am publishing using artifactoryPublish, which includes the artifacts created after running assembleRelease. So, basically how do I make assembleRelease produce a binary that includes my local dependency?
Just publish coreLibrary in the maven repo.
Then in your exportLibrary change the dependency with:
implementation "com.xxxx.coreLibrary:x.y.z"
and publish it in the maven.
At this point if you check the pom file of exportLibrary in the repo you will find the dependency to com.xxxx.coreLibrary:x.y.z.

How to export dependencies in android library

Since version 3.0.0, the Android Plugin for Gradle allows you to export a module's dependencies to other modules.
As I understand it, this means that in my android library module I should be able to declare a dependency using api <dependency declaration> and access THAT dependency as an exported transitive dependency in my main app project, where I've declared my library module as a dependency.
I'm also using static file dependencies.
As an example:
I have a class NeededEverywhere, which is defined in its own gradle module everywhere-module. This module is in the same project as my library module.
//library module's build.gradle:
dependencies {
api project(':everywhere-module')
}
In my app's build.gradle (which is in a different Android Studio project), I declare my dependency on the library, but not the everywhere-module. This should mean that everywhere-module is an exported transitive dependency.
//app project's build.gradle
dependencies {
implementation files("path/to/my/library/file.aar")
}
However, I can't access the class NeededEverywhere in my app.
What am I doing wrong?
You are directly referencing an AAR.
Dependency information is not in an AAR, any more than dependency information is in a JAR. Dependency information is held in the metadata of an artifact repository, such as the POM file of a Maven-style repository.
So, the project with the library module needs to publish its AAR to an artifact repository. That could be one local to your machine (e.g., mavenLocal()). Then, projects that need to depend upon the library module do so from the repository, not via file(). Then, Gradle can get the transitive dependency information from the repository and make use of it.

AAR file updation when imported and added as a module in an Android project

I am using a library by importing the aar file which creates a module. And this module is then added as a dependency.
I did it for one of the libraries I'm using in my app and it worked fine. But now I want to update to the latest version of the library I'm confused about the following:
How do i find out which version I'm using? Don't remember what the version was when i imported the aar file. Is there a way to check this?
I want to update the aar with its latest version. How do i do that? Do i simply re-import and it will overwrite? or do i delete the existing module and import again?
I found only this one related post on SO and it did not answer any of the above two questions. It suggests another way of using the aar but I want to know how to continue using the import aar approach.
The aar file in question is that of millennial-media
How do i find out which version I'm using? Don't remember what the version was when i imported the aar file. Is there a way to check this?
There isn't a standard way to know the version of your aar.
You can use the name or a file inside the aar or you can simply use doc.
I want to update the aar with its latest version. How do i do that? Do i simply re-import and it will overwrite? or do i delete the existing module and import again?
You can simply overwrite the aar file.
Importing the aar file means:
copy the aar file in a folder
add the dependency and the repository in the build.gradle
Somenthing like:
repositories {
flatDir {
dirs 'libs'
}
}
and add the dependency:
dependencies {
compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
}
When you want to update, just copy the aar file overring the exiting file.
I suggest you using a maven dependency. In this case someone uploaded the library in a maven repository.
Currently it is the best solution in my opinion.
In this case just add a dependency in your project
dependencies{
compile 'group:name:version'
}
and it is very simple to know the version and to update the library.

Android can't find the third library on AAR

My AAR includes a picasso library, but in my java code can't find picasso.
Here is my build.gradle:
and here is my multi-image-selector AAR gradle:
Why you not using only
compile 'com.squareup.picasso:picasso:2.5.2'
The aar file doesn't contain the nested 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 you have to add in your app (not the library):
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
If you use the gradle maven plugin to deploy the aar to a local repo, then you can get transitive dependencies to work. Here's how to do that:
How to use maven plugin to publish a library as an aar
How to enable transitive dependencies on the library dependency
Assume that you have one app and one library module. In your library module you use Picasso as dependency.
Let me explain step by step, with possible scenarios.
1- If you add your library module to your app module as the following :
implementation(project(":myLibrary"))
Your library works correctly.
2- If you add your library module to your app module as the following :
implementation files('../libs/mainLibrary-debug.aar')
You may get a crash if you don't put Picasso dependency to your app module. You have two options to get rid of this crash.
2.a.First option is to add Picasso library to your app module.
2.b.The second option is to compile you aar using any fat aar plugin. If you use a fat aar plugin, when you generate aar, it automatically downloads Picasso library and put it in aar. In this way, you don't need to add Picasso dependency into your app module. There are several fat aar plugins available, here is one of them : https://github.com/kezong/fat-aar-android

Multiple AAR files

I am using Android Studio 1.2
I create a private library I want to use that one in another application.
To use it I create an AAR files, but this AAR don't work. I have in my library a dependency to an AAR file.
The AAR files do not the dependencies?
If I use the jar and I includ ans create all the dependencies the project works fine.
NOTE :
I know how to importe the AAR file. The problem is to use an AAR in the AAR..
Thanks.
If I'm understanding your question correctly, there are 3 projects involved:
Library Project 2 --> Library Project 1 --> Application Project
You are editing "Library Project 1" and have added to it's app/build.grade a dependency on the Library Project 2's aar. Something like this: compile 'com.arasthel:gnavdrawer-library:1.1.5'
I am not sure where you are running into an issue, but I'll attempt an answer anyway. If I'm completely off-base, can you please elaborate on how the AAR dependency is not working? Any error messages?, a class/resource not found, etc.
I think it's unlikely you are unable to use a class from Library Project 2 inside Library Project 1, because I just tried this myself and it seems to be working just fine. It's worth noting that the Library Project 1 aar file will NOT include classes or resources from Library Project 2. Library Project 2 will be noted as a dependency in Library Project 1's pom if published using gradle's maven plugin to publish Library Project 1.
My guess is that you are having a problem in the Application Project? Perhaps the class from Library Project 2 is not found in the Application Project?
If that is correct, then there are two possible solutions:
Enable transitive dependencies on the aar dependency in the Application project's app/build.gradle: Instead of compile 'com.example:myLibrary:versionX', make it compile('com.example:myLibrary:versionX'){transitive=true}. I just verified this causes gradle to read Library Project 1's pom and automatically add dependencies found there into the Application Project.
If you would like to use transitive dependencies, your Library Project will need to be generating a pom and publishing it along with the aar. See https://stackoverflow.com/a/30085677/431296 for some additional information on how I have this working.
Manually add the dependency on Library Project 2 to the Application Project - so that your Application has a dependency line for both Libraries. Depending on your specific situation this may or may not be a workable solution.
Add following code to you project build.gradle file, and you should put you AAR file to the libs folder.
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
And finally add compile info to your dependencies:
dependencies {
compile(name:'AARFileName', ext:'aar')
}

Categories

Resources