79552380

Date: 2025-04-03 08:36:57
Score: 0.5
Natty:
Report link

Introduction

I have been coming across this topic in my searches quite a bit as I always seem to hit blockers when implementing needed functionality on the various devices I compile to for Android. Perhaps the following thoughts can demystify the .aar file and how one can use it in RAD Studio. As of RAD Studio 12.2 you can apparently just add the .aar file to your project but it is not clear how to reference it in code.

.aar and .jar files are zip files

It is true that the .aar file is merely a zip file, it is easy to rename and extract the contents. A lot of libraries are distributed in this format and work really nicely in Android Studio by simply including the files in the gradle build. The .aar file in many cases contains a jni folder which contains the c++ libraries for the supported android OS, either 32 bit or 64 bit.

.so files from jni can be added to RAD Studio project

These .so files need to be included separately as part of the RAD Studio Deployment on the Menu(Project -> Deployment). It is also here where you can deploy any res files that are part of the .aar library which you have extracted. Inside the .aar library is a classes.jar file which also can be extracted and renamed then added to your project under Libraries (Android Target).

You can manually merge multiple .jar and .aar files together

I have successfully combined multiple .aar files into a single .jar file by extracting each classes.jar file then merging each of their contents together in a single .jar file. Once this has been done the initial hard work is over. Running JAVA2OP on this .jar file will result in a .pas file which you can include in your project. The only issue here being that all the dependencies need to be resolvable in the .jar file. So if the code in the .jar file relies on some 3rd party library code, you will need to download that package and include it in your .jar file.

Make sure you have all the dependencies covered

In principal when I do these builds I still check if the libraries I build in Android Studio actually work with a test application. If I am simply building a module / library in Android studio I start it by building a "blank" Android application then add a module which is essentially a folder within the project.

Summary

Conclusion

I find that this topic is not very well documented and frankly very black boxed. Even keeping up with all the changes in Android is difficult for me (Manifest!) Let me know if I need to clarify anything better, I put this here in the hopes that it will help.

Lastly, you cannot build multiple .aar files into a single .aar module without much pain, don't waste energy trying that!

Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Andre Van Zuydam