I know from some other answers that including dependencies into an aar library is discouraged as the one using the aar should be able to include them by himself.
But I have a bunch of local maven dependencies that I would like to include with the aar. I could of course just include the .jar's. But there is a quite a few dependencies and if I update them I need to get all separate jars and update them as well in my aar. And using compile 'maven repo...' is quite handy.
So my question is, can I some how force my local maven repos to be included in the .aar?
Related
I have a multi module android project and currently anyone in our team can access the the modules from our private maven repository.
We are using jFrog Artifactory hosted in aws for managing the repositories. The structure of our project is something like this
app
-lib1
-lib2
-lib2a
-lib2b
I want to know if there is a way by which lib2a and lib2b is not accessible as separate modules but only accessible when someone adds the dependency of the parent module in their project which is lib2 in this case
I want to know if there is a way by which lib2a and lib2b is not accessible as separate modules but only accessible when someone adds the dependency of the parent module in their project which is lib2 in this case
Short answer:
No, you can't do it.
Long answer:
When you put an artifact in a maven repo you have the artifact files (may be an aar for your android libraries) and a pom file.
The pom file describes also the transitive dependencies of the artifact.
Currently you can't specify a parent dependency or a specific maven repo to be used (this one is under development).
It means that a build system, for example gradle, read the dependency, download from the repos the pom file and download all transitive dependencies.
When you download a transitive dependency there is no way to specify if you have just downloaded the parent or if you are directly downloading it.
It can be available, or not available without conditions.
I created a library 'LibA' which has dependencies on many 3rd party libraries like RecyclerView, EventBus etc. When i tried to include it in another project as an aar, Library was included successfully but dependencies did not came in aar.
Q1 How can I include dependencies in LibA, so that when some other project includes this library, it should not worry about internal dependencies of my library.
Q2 How does gradle manages dependencies of libraries, does it downloads all depenedencies at once, or first checks which are already available in the main project?
Q3 When someone includes a library from jcenter, does that brings all the dependencies with it?
Any help will very much appreciated. :)
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.
Q1 How can I include dependencies in LibA, so that when some other project includes this library, it should not worry about internal dependencies of my library.
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.
Q2 How does gradle manages dependencies of libraries, does it downloads all depenedencies at once, or first checks which are already available in the main project?
Gradle handles the dependencies for you. It doesn't add the same dependency twice or more.
Q3 When someone includes a library from jcenter, does that brings all the dependencies with it?
As said before, in this case the dependency has a pom file which describes all the nested dependencies. Gradle downloads it automatically.
Q1 How can I include dependencies in LibA, so that when some other project includes this library, it should not worry about internal dependencies of my library.
You should use some Dependency manager. For example Maven Central which has .pom file which defines all additional dependencies which should be used
Q2 How does gradle manages dependencies of libraries, does it downloads all depenedencies at once, or first checks which are already available in the main project?
gradle downloads all necessary dependencies. It creates a graph for dependencies, try to solve conflicts and download them
Q3 When someone includes a library from jcenter, does that brings all the dependencies with it?
If additional dependencies were not defined in pom file they will not be downloaded, only library
Feel like Im going mad here - this must be so simple!
I have an android aar which I have built from gradle assembleRelease and also using the maven-publish plugin. I thought that /libs/ was included by default but evidently not.
Android tools site shows its an optional include
http://tools.android.com/tech-docs/new-build-system/aar-format
but for the life of me I don't see where this is configured.
I have asked a related Q Include folder in Gradle artifact but I dont see this as a duplicate as thats a generic gradle question really whereas this is aar specific and may be solved outside of gradle.
Edit I have also asked on the Gradle forum
The aar packages local libraries in libs/ so you need to have local jar dependencies.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
When the maven plugin runs uploadArchives then it will create a pom file that tells maven or gradle what dependencies your aar needs. Gradle will handle downloading the jar files and placing them in your class path for the build.
I commented on your other question as well
*reference: https://maven.apache.org/pom.html#Dependencies
*=gradle is backed by maven for dependency management so artifacts available to maven are also available to gradle and vice versa
my problem is simple:
in the web there are numerous ways and tutorials on how to include jars in an android application through eclipse, android studio etc.
I want to do it manually; so, I want to know which files do I have to edit to bind my app
with the specific jars.
in the web there are numerous ways and tutorials on how to include jars in an android application through eclipse, android studio
That is because the use of third-party libraries is tied to the build system being used to build the app.
I want to do it manually
It is unclear what "manually" means in this context.
If you mean that you are using Ant, just put the JAR(s) in your project's libs/ directory, and you are done. Note that this will work with Eclipse as well.
If you mean that you are using Gradle, you will need something like this in your build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
Or, if the JARs can be found in a Maven or Ivy repository, you can reference those as well, by defining the repository in the repositories block and then simply specifying the artifact in the compile directive:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:11.0.2'
}
I want to use Maven Dependencies injections in my Android Project. The goal of this is not to include the libraries into the project but to bind them during runtime. However, I was wondering if the internet connection is slow what is going to be happen? Will the project crash? Will it become slow in compared with the occasion that I had include the libraries into the app?
You are mixing something up here. Maven doesn't do dependency injection. That's a spring term. Maven does build management which helps you adding the correct jars while your application gets built.
The necessary libraries are downloaded from the internet (or your local repository) when you compile your application. This is not done when the application is executed! Maven can add the correct jars in the right versions to your jar (if you configure Maven to do this).