Search code examples
androidzipaar

Modifying contents of Android .aar file / Converting to and from .zip format


I have a .aar file which has a file I need to remove from inside it.

I am running on macOS and changed the extension from .aar to .zip and unzipped the zip file. I then removed the file from the folder, re-compressed it back into a .zip and then tried changing the extension from .zip back to .aar.

The problem is that the now modified .aar is not recognized as a .aar file. It is still being registered as a .zip and I can no longer use it in my project.

How can one easily modify the contents of a .aar file and how do you properly convert to/from .aar and .zip?


Solution

  • Supposing you have mylib.aar in your current directory, try the following:

    $ unzip myLib.aar -d tempFolder # or other extracting tool
    # Change whatever you need
    $ jar cvf myNewLib.aar -C tempFolder/ .