Utilizar ficheros .aar en eclipse

01 October 2014



Cada vez es más normal encontrar librerías para Android en formato .aar. De hecho, muchas de las bibliotecas que forman parte de la "L" Developer Preview sólo están disponibles en este formato. Si usas Android Studio no vas a tener ningún tipo de problema para hacer uso de estas, el problema viene si trabajas con Eclipse. Hasta hace poco, el plugin de maven para Eclipse, no soportaba este tipo de archivos. Por suerte, este plugin ya soporta ficheros .aar. Os dejo un link al tutorial de cómo instalar el plugin en eclipse. Es posible que esta sea la forma más cómoda, siempre que tengas conocimientos de maven y vayas a crear un proyecto nuevo. Si no es así, si no tienes conocimientos de maven, de cómo crear un fichero pom o ya tienes un proyecto creado, es posible que busques otra forma de poder utilizar la librería .aar sin tener que pasar por el plugin de maven para Eclipse. Más adelante voy a describir los pasos a seguir para poder usar la librería en Eclipse sin tener que usar el plugin de maven, pero antes vamos a ver qué es un fichero .aar. Un fichero .aar no es más que un fichero zip con el siguiente contenido:

  • /AndroidManifest.xml (fichero obligatorio)

  • /classes.jar (fichero obligatorio)

  • /res/ (carpeta obligatoria)

  • /R.txt (fichero obligatorio)

  • /assets/ (carpeta opcional)

  • /libs/*.jar (carpeta opcion)

  • /jni//*.so (carpeta opcional)

  • /proguard.txt (fichero opcional)

  • /lint.jar (fichero opcional)


Como verás, dentro del fichero .aar tienes todo lo necesario para poder hacer funcionar la librería en eclipse.

  1. Créate un nuevo proyecto (a partir de ahora proyecto librería) en tu workspace. No te olvides de marcarlo como librería.

  2. Deja vacía la carpeta src del proyecto librería.

  3. Descomprime el fichero .aar. Puedes renombrarlo a .zip y descomprimir o usar alguna herramienta.

  4. Copia el fichero classes.jar del fichero .aar a la carpeta libs del proyecto librería.

  5. Reemplaza la carpeta res del proyecto librería con la carpeta res del fichero .aar.


Ya has creado el proyecto que contiene casi todo lo que necesitas. Ahora vamos a ver cómo configurar tu proyecto para hacer referencia al proyecto librería

  1. En el proyecto en el que quieres utilizar la librería (a partir de ahora, proyecto objetivo) añade como dependencia el proyecto librería.

  2. Abre el archivo AndroidManifest.xml dentro del fichero .aar y asegúrate de copiar todo lo que haga falta (permisos, actividades, servicios, receivers...) en el fichero AndroidManifest.xml del proyecto objetivo.

  3. En caso de existir, copia todo el contenido de la carpeta assets del fichero .aar en la carpeta assets del proyecto objetivo.

  4. En caso de existir, copia todo el contenido de la carpeta libs del fichero .aar en la carpeta libs del proyecto objetivo.

  5. Haz un Clean del workspace y vuelve a compilar.


En principio, debiera funcionar sin problemas. No obstante esto está sujeto a cambio, ya que funciona con la estructura del actual fichero .aar.




It is increasingly common to find libraries for Android in .aar format. In fact, many of the libraries which are part of the "L" Developer Preview are only available in this format. If you are using Android Studio you will not have any problem using them, the problem comes if you work with Ellipse.



The maven plugin changed recently, so now it is able to supports this kind of file. Here is a link to a tutorial on how to install the plugin in Eclipse. Possibly this is the easiest way to do it if have knowledge about Maven; If you have no knowledge about Maven, pom files or you already have an old project, you may find another way to use the .aar file without having to go through the Maven plugin for Eclipse.


I´ll describe below the steps to use the library Eclipse without using the maven plugin, but first let's see what a .aar file is:

 

  • /AndroidManifest.xml (mandatory)

  • /classes.jar (mandatory)

  • /res/ (mandatory)

  • /R.txt (mandatory)

  • /assets/ (optional)

  • /libs/*.jar (optional)

  • /jni//*.so (optional)

  • /proguard.txt (optional)

  • /lint.jar (optional)


As you can see, inside the .aar file you have everything you need.

  1. Create a new project (henceforth, "library project") in your workspace. Do not forget to mark it as library.

  2. Clear the src folder of the library project

  3. Unzip the .aar file. You can rename it to zip and then unzip it or use any tool

  4. Copy the classes.jar file to libs folder on the library project

  5. Replace the res folder on library project with the res folder of the .aar file.


You've already created the project that contains almost everything you need. Now let's see how to configure your project to reference this library project

  1. In the project you want to use the library (henceforth, "target project") add the library project as a dependency

  2. Open the AndroidManifest.xml file inside .aar file and make sure to copy everything it takes (permissions, activities, services, receivers ...) in the AndroidManifest.xml file of the target project

  3. If there is, copy the entire contents inside the assets folder of the .aar file to the assets folder of the target project

  4. If there is, copy the entire contents inside the libs folder of the .aar file to the libs folder of the target project

  5. Clean and Rebuild your target project


It should works like a charm. However this is subject to change because this is all based on the current AAR packaging.
Utilizar ficheros .aar en eclipse

Deja un comentario

Escrito por:

Rubén Rodríguez

Android
Android.aareclipse

Utilizamos cookies propias y de terceros para mantener la sesión o sus preferencias, recopilar estadísticas y proporcionar contenidos conforme a sus intereses. Si continua navegando, utiliza los servicios de la web o pulsa el botón, está aceptando su instalación y el uso que hacemos de ellas. Puede obtener más información sobre como revocar su consentimiento o cómo cambiar la configuración en este enlace.