[SCRIPT] Repack multiple APKs with proper compression settings (and other stuff!)

Search This thread

mudhi

Senior Member
Jul 7, 2010
338
248
54
Taiwan
.dat and .bin are also must be excluded, because when compressed, some proprietary app cannot functioning correctly.
 
  • Like
Reactions: omniwolf

omniwolf

Senior Member
Jan 13, 2005
997
474
sydney
new version

hello, i finally got off my ass and updated to v1.5

it can now optimise PNGs, i just use the standard "work it out yourself" -o1 optimise level. There is a

performOptiPNG

boolean variable you can change to false if you don't want it to do this.
i also added .bin and .dat as suggested by mudhi.

check the first post for details and downloads
 

mudhi

Senior Member
Jul 7, 2010
338
248
54
Taiwan
hello, i finally got off my ass and updated to v1.5

it can now optimise PNGs, i just use the standard "work it out yourself" -o1 optimise level. There is a

performOptiPNG

boolean variable you can change to false if you don't want it to do this.
i also added .bin and .dat as suggested by mudhi.

check the first post for details and downloads

Yes, optipng works, slow but still faster than using apk manager. :D
 

omniwolf

Senior Member
Jan 13, 2005
997
474
sydney
v1.5.1

Hello,

I have released v1.5.1, this version sees some code clean ups (i had some ugly code that i actually don't know how it worked.. it shouldn't have from what i can see!), and i have added in a new editable variable:

verboseOutput

it's set to false by default, but if you turn it on you'll get console echo's of where the script is up to, like this:

attachment.php


make sure you run it from the command prompt as you can see i have above, and run it with cscript.

enjoy.
 

Attachments

  • fixAllAPKsOutput.jpg
    fixAllAPKsOutput.jpg
    44.5 KB · Views: 552

steal25

Inactive Recognized Developer
First off thanks for the great tool!!

im getting this error
script: C:RemoveDebuggingInfo....
Line: 133
Error: File not Found
Code: 800A0035
Source: Microsoft VBScript runtime error

i check the script and this is line 133 - buildRunDeflateCMD(fileObj.name)


Any help help would be great.
 

omniwolf

Senior Member
Jan 13, 2005
997
474
sydney
First off thanks for the great tool!!

im getting this error
script: C:RemoveDebuggingInfo....
Line: 133
Error: File not Found
Code: 800A0035
Source: Microsoft VBScript runtime error

i check the script and this is line 133 - buildRunDeflateCMD(fileObj.name)


Any help help would be great.

that's weird, where are you running the vbs file from? did you copy it into the root folder of your extracted ROM? i thought maybe that error could happen if there were no APKs, but i just tried it and it didn't fail with no APKs.

the other thing that concerns me i've bolded in your quote above, why is that all misformed? why doesn't it have the acutal fixAllAPKs.vbs script name in it? when i get a runtime error in vbs it gives me a proper folder path, eg:

Script: E:\downloads\temp\fixAllAPKs.vbs
 

steal25

Inactive Recognized Developer
that's weird, where are you running the vbs file from? did you copy it into the root folder of your extracted ROM? i thought maybe that error could happen if there were no APKs, but i just tried it and it didn't fail with no APKs.

the other thing that concerns me i've bolded in your quote above, why is that all misformed? why doesn't it have the acutal fixAllAPKs.vbs script name in it? when i get a runtime error in vbs it gives me a proper folder path, eg:

Script: E:\downloads\temp\fixAllAPKs.vbs

Thank you for you reply, i tried and ran successfully this mornig.

i didnt caopy and paste the error verbatim, i type it out so i didnt write in the full path, here is the full path

C:\RemoveDebuggingInfo_v2.2\fixAllApks.vbs

for whatever reason its working now and i really appresiate this tool. Thank you again.
 

omniwolf

Senior Member
Jan 13, 2005
997
474
sydney
OK good to hear.
probably next time you're typing out an error message for someone to try and debug, you should type the whole thing out verbatim.. a stitch in time, etc ;)
 

varun.chitre15

Inactive Recognized Developer
Oct 23, 2011
3,153
15,403
Sangli
Great script!!
Can it be in .exe?(no problem with this but just a suggestion :D)
Any plan to add UI to this script?


Sent from my Micromax_A70 using Tapatalk 2
 

varun.chitre15

Inactive Recognized Developer
Oct 23, 2011
3,153
15,403
Sangli
I am getting error
Code:
Script : D:\ROM\A60\fixAllAPKs.vbs
Line: 61
Char: 2
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error

Help please :(
 

omniwolf

Senior Member
Jan 13, 2005
997
474
sydney
Great script!!
Can it be in .exe?(no problem with this but just a suggestion :D)
well i guess technically anything is possible, but i won't be compiling this into an EXE. the scripting paradigm works well for this task, an exe would be overkill IMO.

Any plan to add UI to this script?
Not really possible without using HTA or compiling it on another language.. if you want to covert it over be my guest :) i don't think it's worth the effort, all the variables are absolute, so you should only ever have to set them once, which means a UI wouldn't be that useful.


I am getting error
Code:
Script : D:\ROM\A60\fixAllAPKs.vbs
Line: 61
Char: 2
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error

Help please :(

Line 61 references a temp dir you're supposed to have created:

tempAPKBuild = "D:\Temp\tempAPKBuild"

the comment above says:

' if your tempAPKextract or tempAPKBuild variables below are subdirs, for example "C:\Temp\tempAPKExtract", you must make sure
' the root directories (in this case "C:\Temp") are already created. I can't be bothered creating them for you :)

have you done this?
i'm guessing you haven't altered this variable, and you don't have a D:\Temp folder and/or drive.
probably in the next version i'll try and put the temp locations in a spot everyone already has to fix these noob errors..
 

Saah88

Member
Feb 11, 2013
15
1
Signing?

Wow, it does everything, except what i really need - signing all apks in a rom.
Or is there a tool which signs all apks in folders and subfolders of a ROM root directory ?

Edit:
i have extracted framework-res.apk from the released ROM zip file,
then decompiled it,
then edited resource files,
then build (from ApkTool)
i can skip zip-aligning,
but now i HAVE to sign it with the same key, the ROM was originally signed [OR] resign the whole ROM and every apk in it with my signing key, right?
elsewhere i just get BootLoops on CM 10.1 JellyBean 4.2.2 ROM

Edit 2:
Finally i found a proper guide to not end up with a bootloop:
http://xdaforums.com/showthread.php?t=1783525
followind that guide i dont need to resign all apks, i dont even need to sign modified framework-res.apk, just to build it properly with some original files copied, more about it at "-Decompiling and compiling APKs-" spoiler > "Step 4 (proper compilation)"
 
Last edited:

omniwolf

Senior Member
Jan 13, 2005
997
474
sydney
OK, if you need signing as part of my script, and you can show me a command line way to do it, i'll happily add it in.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 16
    Hi Guys,

    I was speaking to baadnwz a couple of weeks ago and i asked him which script he used to properly pack all the APKs in his ROM. He told me he used no script, just repacked the APKs he thought were most relevant.
    I figured it couldn't be too hard to write something that took an APK, extracted it somewhere, then repacked it with the proper compression, so i wrote one. baadnwz then challenged me to make it work for multiple APKs, so he can just run it against a folder full of them like a lazy asshole. i went one better, and made a script that you could run against a ROM folder structure, it will search out all APKs, repack them, and copy them back into place. HOT!

    because this uses recursion and functions to make it easier to write (and because i'm generally comfortable in it), i have written it in VBScript. So this means it won't work on linux as far as i know, sorry. Feel free to convert it or whatevs

    WHAT DOES IT DO??????//
    1. finds an APK
    2. unpacks it in a folder
    3. optimises the PNGs (if you want it to)
    4. repacks all files as deflate except a blacklist of filetypes*
    5. repacks the blacklisted filetypes* as STORE
    6. zipaligns the new APK

    7. copies it back to the original location, overwriting the original APK
    8. finds the next APK, and repeat from step 2

    * the blacklisted file types are easily editable. just find the STOREFileNames variable. by default the filetypes are:

    "*.arsc", "*.m10", "*.png", "*.wav", "*.ogg", "*.mp4", "*.jpl", "*.jpeg", "*.gif","*.mp2", "*.mp3", _
    "*.aac","*.mpg", "*.mpeg", "*.mid", "*.midi", "*.smf", "*.jet","*.rtttl", "*.imy", "*.xmf", _
    "*.m4a","*.m4v", "*.3gp", "*.3gpp", "*.3g2", "*.3gpp2", "*.amr", "*.awb", "*.wma", "*.wmv", _
    "*.so", "*.dat", "*.bin"

    WHY DO YOU WANT THIS??
    If certain filetypes in the APK are compressed as STORE (which means they aren't compressed at all), then Android can use them directly. If they are stored as DEFLATE (like all other file types should be), then Android must first decompress the APK somewhere. This means slower apps, more cache, and it's just not how things are supposed to be done. This script makes sure that all files inside all APKs are stored as they should be, and it will optimise PNG files and zipalign the final APK as it goes.

    This script is really meant for ROM chefs to run against their ROMs before releasing them, but if you (a mere user) have a ROM that your chef hasn't run this script on, then you can extract the ROM, run the script on it, then recompress the ROM and flash it.

    HOW DOES IT DO IT?????///////
    • It uses the command line version of 7-Zip. Download it from here:
      http://7-zip.org/download.html
    • It uses zipalign.exe from the android SDK. if you don't know where this comes from.. maybe you shouldn't be using this script :)
    • It uses a cool OptiPNG utility to optimise the PNGs if you want it to. This slows the processing down a lot.. but it's up to you if you wanna do it. You'll need to download the utility from here:
      http://optipng.sourceforge.net/


    WHAT DO I HAVE TO DO TO MAKE IT WORK//////?
    1. Grab the script, put it in the same folder as the root of your ROM (the script will repack all APKs in the subfolders from where it's sitting, including the APKs in the folder the script is in).
    2. open up the script, there are 5 variables you MUST verify, most likely you will have to change them.. unless you put things on a D and E drive and your name is Nick..

      tempAPKextract = "E:\Temp\tempAPKExtract"
      tempAPKBuild = "E:\Temp\tempAPKBuild"
      sevenZipLoc = """D:\nick\android\7za\7za.exe"""
      zipAlignLoc = """D:\nick\android\android-sdk-windows\tools\zipalign.exe"""
      optiPNGLoc = """D:\android\7-zipA\ROM\optipng.exe"""


      the first two temp ones can be anywhere.. just make sure at least the sub folders up to "tempAPK..." exist (eg in this case the E:\Temp folder must already be there)

      the next three are the locations of the tools required for the script to work, edit to please!
    3. Run the script. If you have set verboseOutput to true (it's false by default), then I would highly recommend you run the script from the commandline with the command:

      cscript fixAllAPKs.vbs

    anyways, hope it's useful to you.

    DOWNLOAD

    CHANGELOG????/
    v1.5.1 - cleaned up some code, added in verboseOutput so you can watch the progress as it's fixing (must run as cscript!)
    v1.5 - added OptiPNG to the script, enabled by default. Quite slow. Added some more file types.
    v1.4.3 - added more file types to STORE, thanks gtg465x
    v1.4.1 - minor code clean up, fixed some comments.
    v1.4 - fixed the problem where the script wouldn't fix any APKs in the root folder that the script was in
    v1.3 - almost doubled the speed of the script. fixed some naughty bugs
    3
    v1.5.1

    Hello,

    I have released v1.5.1, this version sees some code clean ups (i had some ugly code that i actually don't know how it worked.. it shouldn't have from what i can see!), and i have added in a new editable variable:

    verboseOutput

    it's set to false by default, but if you turn it on you'll get console echo's of where the script is up to, like this:

    attachment.php


    make sure you run it from the command prompt as you can see i have above, and run it with cscript.

    enjoy.
    2
    new version

    hello, i finally got off my ass and updated to v1.5

    it can now optimise PNGs, i just use the standard "work it out yourself" -o1 optimise level. There is a

    performOptiPNG

    boolean variable you can change to false if you don't want it to do this.
    i also added .bin and .dat as suggested by mudhi.

    check the first post for details and downloads
    1
    Heres the link to the opensource OptiPNG program to optimize a PNG

    http://optipng.sourceforge.net/
    1
    .dat and .bin are also must be excluded, because when compressed, some proprietary app cannot functioning correctly.