Android library .aar file contents - android

We are evaluating a third party SDK to integrate with our Android app but the problem is that the third party company doesn't have any repo (eg: Maven) support. They are providing an Android module that needs to be imported (which consists of several .aar files, .java files, .manifest file and few assets). I don't understand why they are not providing a single .aar file that includes all of these, are there any technical challenges in doing that? The problem at our side is that we are using a local Nexus repository and we will have to manually upload this module and unzip the contents every time we do a build. Looking for any ideas on how to deal with this problem, thanks.

Related

aar vs "plain module" advantages

if I have a project with many library projects linked, could I improve build performances by packaging each of them in an AAR and including it in the main project ? Or this will not make any difference since that when the compiler need to assemble the apk it need to package everything together anyway?
Thanks to any one who will give me some clarifcation about performance differences between the 2 approach
I don't think you will save any build time by wrapping an existing .jar file into a .aar file and using that instead of the original .jar file.
As this SO post notes, .aar files are basically just zip files which may contain a jar file and some android resources.
Also, because .aar files are not precompiled into Dalvik byte code, the build process for your apk file must still carry out that step at least once. So, you won't save dexing time just by wrapping the .jar file into a .aar file either.
If you build a typical Android Studio project (with some Android library dependencies specified in the gradle build file) you can see the directory underneath app/build/intermediates/exploded-aar where these files have been unzipped. That work must still be done by your build machine even though you are using a .aar file.
Finally, as you pointed out, the .apk packaging work must still be done at the end of the build.
I believe the Library projects (which you are using) is the best way to go because of two reasons:
The library project gives the direct access to the code base of the libraries which can be compiled and packaged together with the main app code
In case, multiple .aar files are referenced within the project, then during the apk creation the unpacking, merging of resources and Manifest file will increase the build time.

Shared Library On Android Studio

I'm switching from Elcipse to Android Studio. In Eclipse I have some "library projects" (no jar files, but Android projects marked as "library") that are used by several apps. In Eclipse I used to have this library project in only one place, and I liked to modifiy the library only once, and see the effect on all the other projects depending on it.
In Android Studio, when I add a library module, all the code is copied inside the app. I don't like it, because it's easier to maintain having it only in one place. Is there any way to reference the original library instead of copy it inside the project?
I've been reading a lot of about this, but I can't find the right solution. These are the ways I'm thinking to do it:
a) Aar files and local maven repository: I would compile the library module into an aar file, and I'll save in an local maven repository, so I can reference it on my projects. But this has a drawback: every time I want to modify the library, I need to recompile to an aar file before I can test the changes in my project.
b) Symbolic links: Instead of copy all the library module inside the app folder, I'm thinking in creating symbolic links to the original folder. So the library will stay in only one folder. But I think this approach is so tricky, and there must be a better way to do it.

Creating jar Library of Android project?

I have a project that uses some resources.I want to create a library from it and publish it.I create a jar file with export option of eclipse,but it did not work.Then I search the we b and it seems that way works if and only if project does not use resources.But I saw this post.Here CommonsWare saya there is a way to create a jar file from a project that uses resources.But that answer has two link that do not open any page on the web and I could not test CommonsWare's answer.So my question is:
Is there any way to create jar library file from project that uses resources?
Note:
I read docs that say:
If you have source code and resources that are common to multiple
Android projects, you can move them to a library project so that it is
easier to maintain across applications and versions.
But as I said before,I want to publish my jar and docs say we can not create jar file from library project.And so I can not publish it.
Here CommonsWare saya there is a way to create a jar file from a project that uses resources.
Not in that answer. You can tell that by actually reading the answer.
But that answer has two link that do not open any page on the web
Sorry, Google reorganized their site and broke the original links. The answer has been updated with current links.
Is there any way to create jar library file from project that uses resources?
No.
You can create an Android library project that includes a JAR instead of Java source code. AFAIK, this recipe still works:
Create an Android library project, with your source code, resources, and such, and get it working
Compile the Java source (e.g., via Ant) and turn it into a JAR file
Create a copy of your original Android library project to serve as a distribution Android library project
Place the compiled JAR from step #2 and put it in libs/ of the distribution library project from step #3.
Delete everything in src/ of the distribution library project (but leave the now-empty src/ directory there)
Distribute the distribution library project (e.g., ZIP it up)
And the new Gradle-based build system supports the AAR package for distributing libraries and such, though I have not played with this yet.

Create a JAR for Android Library Distribution

I am working on an android library, and wish to export a JAR file that I can distribute for others to use in their apps. I don't want to distribute the source code as it contains details on posting to my web server.
I have tried using the JAR file that is created in the bin directory and copying the jar file to my project and referencing it within my project and ticking the export button.
When I try and run my project referencing the library that I've copied, my app throws an exception with NoClassDefFoundError. I've done some Googling and everything I have found suggests you have to provide the source code and let the user import into their IDE and then reference that project into their app which I don't want to do. It must be possible as other companies provide JAR files for libraries that can be included.
Thanks for your help.
I don't want to distribute the source code as it contains details on posting to my web server.
Bear in mind that anyone who wants to can get that data out of the JAR.
It must be possible as other companies provide JAR files for libraries that can be included.
AFAIK, this recipe still works:
Create an Android library project, with your source code, resources, and such, and get it working
Compile the Java source (e.g., via Ant) and turn it into a JAR file
Create a copy of your original Android library project to serve as a distribution Android library project
Place the compiled JAR from step #2 and put it in libs/ of the distribution library project from step #3.
Delete everything in src/ of the distribution library project (but leave the now-empty src/ directory there)
Distribute the distribution library project (e.g., ZIP it up)
This effectively gives you what you see with the Play Services SDK -- a library project with no source code, but instead a JAR in libs/, along with the resources and such.
I will be reconfiming this recipe tomorrow and will try to remember to update this answer if I find that it needs adjusting for the current crop of tools.
And the new Gradle-based build system supports the AAR package for distributing libraries and such, though I have not played with this yet.
UPDATE
This recipe works, so long as the library project does not itself have dependencies upon another JAR or library project. In those cases, things seem to get messed up in the build process -- everything can compile, but class references from the dependencies cannot be resolved at runtime.
Did you try putting your jar file in libs folder?And if you are exporting a jar library for android be sure it has no /res folder. As you know you can't reference to your res folder from a jar therefore you have to use library project to reference your res folder (drawable,xml,ect...)On the other hand you cant make your code safe (the part you say about posting to your web service) by using it as jar since it is so easy to retrieve by reverse engineering. you better use some encoding (like base64 or any algorithm that bouncycastle provides)

Creating a single distributable jar file for Android projects which includes other jar files

My objective is to create a single distributable jar file for Android projects which includes a few other jar files. As I understand a "standard" jar file is not allowed to have other jar files inside, so guess I need to learn a trick here.
I have been trying to set up One-Jar for this, but I keep hitting
issues. Are there any dev guides for using One-jar with Android projects (using Eclipse)?
Are there any other good alternatives out there I should look at?
jarjar is pretty good at this. When you use it together with Maven its super easy to make a large collection of dependencies a single jar.
Although, there's nothing stopping you including multiple jars as dependencies in an Android project.

Categories

Resources