51

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

I am running on mac and changed the extention from .aar to .zip and unzipped the zip file. I then removed the file from the folder, recompressed 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.

So my question is two fold:

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

user1782677
  • 1,963
  • 5
  • 26
  • 48
  • Right. The problem is that with the latest iOS (Aug 2016), you simply can't remove the .zip extension! if you remove it, it simply adds it again and then hides it. – Fattie Aug 17 '16 at 13:25
  • @Fattie You can remove the zip extension. I just simply unchecked the "hide extension" box. Then I removed the .zip and replaced it with .aar in the file info screen. Hit enter and it should ask you about changing file extension. – Jay Snayder Aug 04 '17 at 20:50

2 Answers2

116

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/ .
Salem
  • 12,808
  • 4
  • 34
  • 54
  • Great tip, I was struggling with an issue to remove libjpeg-turbo.so file from imagepipeline.aar of fresco and the above two line helped me to do so. – shekar Aug 24 '16 at 06:48
  • 1
    Packing with jar utility will generate invalid library file. At least I get an error: "Unable to unzip my-new-library.aar' I'm packing with regular zip: `cd tempFolder; zip -r ../my-new-library.aar *` – DrMoriarty Nov 13 '17 at 08:15
  • When I tried to repackage aar file, I was getting this kind of options list. https://drive.google.com/open?id=1V6KpvJ-6KiWkHEW_1egsJENY7_Dkc8Od – Siddharth Feb 05 '18 at 14:07
  • best n most simple solution – Richard Fu May 23 '18 at 06:52
  • This helped a lot! Thanks! – Tgo1014 Nov 18 '19 at 09:03
27

For extracting following command you have to execute:

unzip myLib.aar -d tempFolder

Do all your changes in your extracted code and using below code you can again repackage it.

You have to move inside the extracted folder to again repackage it, using below code:

cd tempFolder

For repacking of aar file this way is working:

zip -r ../my-new-library.aar *

Above mentioned 3 steps were practically tested by me and its working properly.

Siddharth
  • 4,142
  • 9
  • 44
  • 90