I am a plugin developer, my plugin have dependency of two aar libraries. When i am exporting as aar archive my dependent libraries not part of it.my project structure is like below mentioned
App
lib1
--aartool
lib2
lib3
lib1 has the dependency of lib2, lib3 and aartool files.
App has aar dependency of lib1.
Lib1 using some of the customized components from aartool after that lib1 as converted to aar and used to application.But, whatever file we accessed from aartool which is not available in application and throwing classnotfoundException
Is there any way to implement these dependencies as aar?
Always i need to carry lib1 aar to application, i don't want to carry all other dependencies.
I am not sure I understand it correctly, but I believe you just need to add transitive dependendcies like in this question or in this.
Example:
compile ('com.foo:FOO:1.0.0#aar'){
transitive=true
}
If you have circular dependencies you may encounter serious problems! I strongly recommend you to fix this.
Related
I build an Android Application which contains a module as library. Most of the logic is inside the LibraryModule. The library module has several other dependencies which are included as gradle dependencies
Application
* LibraryModule
*implementation ('dependency1')
*implementation ('dependency2')
The library module is include in the application's build.gradle like
implementation project(":LibraryModule")
The application works fine then.
But when I first build the Library module as an aar file using
gradle :LibraryModule:assemble
and then using the applications build.gradle to include the aar
implementation(':LibraryModule#aar') The application compiles. But several of the classes of the dependencies (dependency1, dependency2) which are required at run time are missing from the aar.
Is there some way to include all the contents of the dependency1 and dependency2 in the aar file so that run time dependecies is also packed together in the aar file.
I have done some googling and found out that fat aar is an option. Is there some way to include all the class file from the dependeices also into the aar file which are also needed at run time ?
Building a fat-aar is not officially supported by Android. There are some similar discussions at Android gradle multiproject dependency resolution
I have two projects that use the same library. This library uses a jar file as a dependency, however only the library is able to read the classes from the jar file. The two projects don't have access to the classes from the jar file.
I tried adding the jar file to the two projects separately, but I get a build error, probably because now it's included in the project level and library level resulting in conflicts.
The jar file is YouTubeAndroidPlayerApi.jar
/------------------- Project1 (can't read classes from jar)
Library(w/ jar)
\------------------- Project2 (can't read classes from jar)
Any ideas on how to approach? Thanks!
If you are using gradle 4.1, make sure to use the api keyword when importing the .jar into your library. Then remove it from your other projects.
for example: api fileTree(dir: 'libs', include: ['*.jar'])
from the documentation:
When a module includes an api dependency, it's letting Gradle know that the module wants to transitively export that dependency to other modules, so that it's available to them at both runtime and compile time. This configuration behaves just like compile (which is now deprecated), and you should typically use this only in library modules. That's because, if an api dependency changes its external API, Gradle recompiles all modules that have access to that dependency at compile time. So, having a large number of api dependencies can significantly increase build times. Unless you want to expose a dependency's API to a separate test module, app modules should instead use implementation dependencies.
Not sure why I can't find any answers on this. If I convert my library project into an .aar using Gradle in Android Studio, does it retain all the dependencies of that module?
I'm asking because I'm trying to use a Gradle generated .aar locally, but it looks like only some of the original dependencies have been packaged. Namely, it complains that I'm missing 'OkHttp', but if I add it to the main project I get duplicate class errors.
Usually a library does not directly contain its dependencies. This does not matter whether it is an aar or a jar. Instead, the library declares its dependencies in the Gradle build file and they are resolved when someone uses the library.
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')
}
I want to package my library as an aar.
The library has several dependencies (universal image loader, ORMLite, guava...)
It also has a dependency for another library that I wrote (call it 'library B').
I have 2 questions:
Will everyone who will use my library need to add dependencies according to the library's dependencies (universal image loader, ORMLite, guava...)
Do I need to create a separate aar for 'library B', and have users of my lib have a separate dependency for it?
Will everyone who will use my library need to add dependencies according to the library's dependencies (universal image loader, ORMLite, guava...)
Not if you are distributing your AAR as an artifact in a repository with appropriate metadata (e.g., Maven-style POM file). The metadata will point to your dependencies, and build systems (e.g., Gradle) will pull in the dependencies.
Do I need to create a separate aar for 'library B'
Yes, otherwise nobody will have access to it, unless you eliminate it and fold its code into your first library.
and have users of my lib have a separate dependency for it?
See above for setting up dependencies.
You don not need do that,and you only do the next:
if you aar libray have thirty dependencies:
you should make others use your aar library in the way:
for example:
compile('com.android:com.android.download:1.3')
or
compile('com.android:com.android.download:1.3#aar'){
transitive = true
}
if your aar libray have not thirty dependencies:
compile('com.android:com.android.download:1.3#aar')
In a word:#aar have conflict with the default vault of transitive