Home > Enterprise >  How work the jar located inside the /libs subfolder of an aar?
How work the jar located inside the /libs subfolder of an aar?

Time:11-23

Inside some aar archives their is a libs subfolder with some .jar in it. What the purpose of those jars? why they are not merged in the classes.jar? If I add the aar as a dependency of my android project, how the jar inside the libs subfolder will be included in the final apk?

CodePudding user response:

The JARs in the libs directory of an AAR are dynamically linked during runtime. Exactly like the JAR files you would provide in the libs directory of your project.

As you may note, the content of an AAR file is similar to the structure of an Android application project -- at minimum a manifest file and the META-INF directory, and further (optional) files and directories. You may find resources (res and/or assets), libraries (native ones in lib, JARs in libs) and so on. Not every AAR files does even contain a classes.jar, as some of theme are only intended to deliver additional res content. That can often be found in compat-AARs.

Basically, during the APK building process one simple thing is made with an AAR file which has been included into the project. It will be unzipped and its files and directories are merged -- at least logically, not necessarily physically -- with their corresponding counterparts in the project. So in your case, the JAR files in the AAR's libs directory are added to the libs directory of your project, where you keep the Java libraries you want to link dynamically during application runtime.

Apart from that the APK building process runs as usual.

In short -- An AAR is a ZIP whose content is merged into the project it was added to.

  • Related