[Tool][Win] GOptimize v1.44 (BASH script for CYGWIN)

Search This thread

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
GOptimize v1.44 (BASH script for CYGWIN)
...is a tool for optimizing PNG's (and JPG's) in Android Applications and recompressing its files.​

Help and Extra Help:
Code:
$ goptimize -he

#####################[ GOptimize v1.44 ]########################
---------------------------------------------------------------#
  usage: goptimize [options] *.apk                             #
################################################################
  GOptimize optimizes APK's with various tools .:. gu5t3r@XDA  #
################################################################
 OPTIONS:                                                      #
  -h   Show Help                                               #
  -he  Show Help + Extra Help (also accepts -hh)               #
  -p   Optimize PNG's                                          #
  -9   Optimize 9-patch (*.9.png) PNG's while optimizing PNG's #
  -m   [1-16] Multi-Threaded PNG optimization; forces -p       #
  -zz  Use ZopfliPNG instead PNGout (More info in Extra Help)  #
  -zo  Use both PngOut + ZopfliPNG for max PNG compression     #
  -q   Convert PNG's to 8-bit with PngQuant with minimum       #
       required quality [0-100]; -q0 to force conversion       #
  -j   Optimize JPG's with jpegoptim; [0] or [75-100]          #
  -e   [-|??] Clean resources of unneeded languages            #
  -a   Recompress resources.arsc with CL[0-6]                  #
  -d   Recompress classes.dex with CL[0-6]                     #
  -b   Remove debug info from classes.dex for API[1-21] with   #
       baksmali/smali; -d[0-6] required; -d5 recommended       #
  -s   [1,2] Force smali v1 or v2 when removing debug info     #
  -l   Recompress libraries with CL[0-6]                       #
  -r   Recompress APK with  CL[0-6]                            #
  -R   [+,-] Smart Recompression modes, read extra help...     #
  -k   Keep only libraries for architecture: 1 armeabi         #
                                             2 armeabi-v7a     #
                                             3 mips            #
                                             4 mipso32         #
                                             5 x86             #
  -t  Sign APK with Android test certificate                   #
################################################################
                         Extra Help                            #
---------------------------------------------------------------#
  PNG Optimization:                                            #
      PNG optimization is lossless and tools used for it are:  #
      TruePNG, PngOut, ZopfliPNG and DeflOpt.                  #
                                                               #
  ZopfliPNG (-z option info):                                  #
      [z] Use ZopfliPNG instead PngOut for better compression  #
       and saving few more kBs at cost of ~20% longer process. #
      [o|b] Use both PngOut + ZopfliPNG for max compression    #
       at cost of extra ~20 longer process compared to [z]     #
                                                               #
  Converting PNG's to 8-bit with PngQuant (-q option)          #
      Converts PNG's to 8-bit with minimum required quality    #
      [0-100]. If quality of converted png is lower than       #
      minimum set threshold original png will be preserved.    #
      -q0 to force conversion; -q100 will skip almost all png  #
      Advanced MIN-MAX thresholds can be used [0-100]-[85-100] #
      PngQuant defaults are -q 45-85; if max threshold not     #
      specified it is set to 100.                              #
                                                               #
  JPG's optimization with jpegoptim                            #
      [0] is lossless optimization and recommended.            #
          It does not recompress jpg's, it just strips all     #
          unnecessary info and optimizes huffman coding.       #
      [75-100] optimizes and recompresses jpg's. Level 95 is   #
          recommended, it will recompress unnecessary big ones #
          and do lossless optimization on other jpg's.         #
                                                               #
  Cleaning resources of unneeded languages with ApkTool v2:    #
      [-]  Remove all unneeded lang. from resources            #
      [??] Keep language with ?? language code                 #
           You can keep multiple languages: -e 'hr en de fr'   #
      [-Ei] Addon option, example "-e 'hr' -Ei" will try       #
            to remove strings that are not required from       #
            required languages except the ones you're keeping. #
            Result: even smaller 'resuorces.arsc'.             #
      If you're cleaning system apps you need to put framework #
      files (framework-res.apk, etc...) in framework directory #
      where apk is located, usually: "PlaceApksHere\framework" #
                                                               #
  Compression Levels:                                          #
      Script always uses 10 passes for compression which       #
      guarantees maximum compression and does not impact       #
      decompression time. Script CL differ in fast bytes.      #
          CL(1) <=>   4 fb        CL(4) <=>  32 fb             #
          CL(2) <=>   8 fb        CL(5) <=>  64 fb             #
          CL(3) <=>  16 fb        CL(6) <=> 128 fb             #
      You can also enter custom fast bytes number to be used   #
      for compression by entering fb[3-258] instead CL.        #
      Examples:   -afb3   -dfb69   -lfb132   -rfb258           #
                                                               #
  APK Recompression (-r option):                               #
      As of v1.25 script uses Smart Recompressing i.e. it      #
      will leave files uncompressed in GOptimized apk that     #
      were uncompressed in original apk which is the best way  #
      for recompressing.                                       #
      -R+ Script will use Smart Recompression plus it will     #
          never compress file formats from below list even if  #
          they were compressed in original apk.                #
      -R- Script will disable Smart Recompress and store       #
          file formats uncompressed only if they are on below  #
          list.                                                #
      Following Android Asset Packaging Tool rules following   #
      list of file formats:                                    #
       "jpg jpeg jpe jfif png gif wav mp2 mp3 ogg aac mpg      #
        mpeg mid midi smf jet rtttl imy xmf mp4 m4a m4v 3gp    #
        3gp 3gpp 3g2 3gpp2 amr awb wma wmv zip lzma xz 7z lua  #
        pxp resS gltxt geo apf zi_"                            #
      should never be compressed as they are already           #
      compressed formats or don't compress well.               #
      Most developers use this file formats for databases and  #
      compressing them would result with application errors.   #
                                                               #
  APK signing with Android test certificate                    #
      Non system apk's and apk's you want to install after     #
      goptimization are needed to be signed. You need Java     #
      configured for signing.                                  #
      Alternative is to patch rom (core.jar) with              #
      Lucky Patcher not to verify signatures.                  #
                                                               #
  Configure Java:                                              #
      To use -b or -e feature you need to enter java bin path  #
      in bin\.JavaPATH file which is usually                   #
      "C:\Program Files\Java\jre[version number]\bin"          #
                                                               #
  GOptimize.cmd Default Options:                               #
      You can edit GOptimize.cmd default options in            #
      bin\.DefaultGO file. GOptimize.cmd default options are:  #
                   "goptimize -p -q50 -j0 -a0 -d6 -l6 *.apk;"  #
################################################################

[+] Download: https://www.mediafire.com/folder/a2z9fpcr4131a

ApkTool: https://www.mediafire.com/folder/7vv4unj5diiu2
Smali (Baksmali): https://www.mediafire.com/folder/p4b4d31bzcuj0
 
Last edited:

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
Changelog:

2016-04-03 v1.44
  • Alowed use of Android API 1-23 for smali (23 is A6.0 MM)
  • Updated smali to v2.1.1
  • Updated ApkTool to v2.1.0
  • Updated pngquant with newest libpng v1.6.21 to v2.6.0
  • Updated jpegoptim with libjpeg v9b to v1.44
2014-12-22 v1.43
  • Don't optimize 9 patch png's by default as ApkTool can't read them and decompile apk after....
  • Alowed use of Android API 1-21 for smali...
  • Updated smali to 686cf35c8e9d7eedc5af5989671917719dfe320a (2014-11-07)
  • Updated ApkTool to 2bd1e595df7dd0743f972845bd5874e8db65cd95 (2014-12-18)
  • Updated pngquant with newest libpng v1.6.15 to v2.3.1 (cc39b47799a7ff2ef17b529f9415ff6e6b213b8f) (2014-12-12)
  • Updated jpegoptim with libjpeg v9a to v1.42 (c6fa01bd56e00b764560b5ad3e1436ef829279c0) (2014-12-22)
2014-07-16 v1.42
  • Don't overreduce colors on 9-patch pngs...
  • Recompiled zopflipng with O3 and some other optimizations for 30% speedup...
  • AutoRepair APK's with bad header...
  • Updated pngquant to v2.3.0 (8d21a4563e)
2014-06-26 v1.41
  • GOptimize now also optimizes 9-patch (*.9.png) png's; To disable optimizing of 9-patch pngs use -9 option...
  • Updated libpng to v1.6.12 and recompiled pngquant with it
2014-06-19 v1.40
  • Updated ApkTool to 2.0.0-RC1-a7b06f161b91dfdf985a717e9713dff5c46688b7 https://github.com/iBotPeaches/Apktool/commits/master
  • Updated pngquant to 2.2.0-860f9fb80fceac2998242ed7c5327da480964d24 https://github.com/pornel/pngquant/commits/master
  • Fix: Removed need for tr.exe. (although I still put it in bin just in case =)
  • Removed posterize because its inferior to pngquant. (-c option is now -q0-100 aka -q0)
  • Improved -Ei option to remove non-required strings from required languages except the ones you want to keep. Works on YouTube now...
2014-06-01 v1.39
  • Changed default action to "goptimize -p -q50 -j0 -a0 -d6 -l6 *.apk;" as pngquant is much better than posterizer and setting -q50 is actually pngquant quality 50-100 so it won't reduce colors more than once no matter how many times you apply it...
  • In v1.38 cleaning of unneeded languages no longer worked with newest ApkTool, so I needed to change my code to read from new ApkTool output and as I were doing it I rewrote code for required strings integration to work better...
  • Compiled with libpng-1.6.10 and lcsm-2.6 and updated pngquant to 2.2 git-917f5e796d9d96ce22af25808e49ff24e4190176
  • Updated jpegoptim to v1.4.1 git-33aabed13dc24e16292405b79a13305059ba453a
  • Updated ApkTool to 2.0.0-RC1-848f0d6b5fb195f73222177ee161e35e6a1e65a6
2014-04-30 v1.38
  • Updated all Cygwin tools
  • Compiled with libpng-1.6.10 and lcsm-2.6 and updated pngquant to 2.2 git-636151dd8e
  • Updated jpegoptim to git--e9dc8ef069
  • Updated zopflipng to zopfli-Hello71-e7778ddedb with bunch of fixes
  • Some script improvements...
2014-04-09 v1.37
  • Added ability to specify advanced MIN-MAX thresholds when using pngquant; it's defaults are -q 45-85
2014-04-09 v1.36
  • Added converting pngs's to 8-bit using PngQuant; -q [0-100] option
  • Updated smali v2 & ApkTool v2
  • smali v2 is now used as default instead v1
2014-03-14 v1.35
  • Updated smali2: 2014-02-02 smali 2.0.3-2d8cbfe6.7z
  • Updated ApkTool v2 to 2014-03-09 ApkTool-GitHub-1e3b66f9be
  • Some layout folders were not removed when cleaning languages on newer apps
  • GOptimize now displays which version of ApkTool is used for cleaning
2014-01-20 v1.34.02
  • Updated smali2 & baksmali2 to 2014-01-18 smali 2.0.3-4357de47
  • Updated ApkTool v2 to 2014-01-19 ApkTool-GitHub-a91e87bb04
2013-12-14 v1.34.01
  • Updated smali2 & baksmali2 to GitHub-eae0b0edbf
  • Updated ApkTool v2 to beta 8 GitHub-d5d03fe1e4
2013-11-27 v1.34
  • Fixed Bug where using a combination of -p, -j and -r options without -R would cause all files to be stored in apk without compression
  • Updated ApkTool v2 to beta 8 GitHub-a1ca5019d8
2013-11-17 v1.33
  • Default options changed to "goptimize -p -j0 -a0 -d5 -l5 *.apk;" because now it auto detects number of CPU cores for PNG optimization. -m option no longer needed.
    You can also use shortcut -pczo for maximum png optimization instead -p -c -zo
  • NEW FEATURE: When cleaning unneeded languages use -Ei option to try to integrate only required strings from required languages to public strings to make even smaller resources.arsc; example "goptimize -e- -Ei *.apk"
    -Ea is alternative apk repacking on cleaning unneeded languages if apk does not work after; you can use both -Eai; -Eia does the same...
  • Updated ApkTool v2 to 2.0.0-Beta8-d2fc74d984 (GitHub)
  • Updated smali v2 to v2.0.2
  • Added defluff to PNG optimization chain for maximum PNG structure optimization
  • Code improvements and cleanup...
2013-10-30 v1.32
  • FIXED Bug in Cleaning languages where optimizing multiple apps would cause required languages to accumulate i.e. detected required languages from above apk would not be removed from below/latter apks because I forgot to reset variables (or make them local).
    Thanks @ct_moi for detection =)
2013-10-29 v1.31
  • Added some code to avoid where Median Cut Posterizer could make some small (<8kB) png's bigger than original.
    I was GOptimizing JEFIT with -czo and freaked out when PNG Savings went -100kB, so I added some code to avoid that =)
  • Updated TruePNG binary to v0.4.1.1
2013-10-26 v1.30
  • Cleaning of unneeded languages works fine as long as ApkTool is able to rebuild apk; only problematic app which gets corrupted is GMail
    Known language codes: af am ar be bg bn ca cs da de el en es et fa fi fr gu hi hr hu id in it iw ja kn ko lt lv ml mr ms nb nl pa pl pt ro ru sk sl sr sv ta te th tl tr uk vi zh zu
  • NEW Feature: -c; Pre-process PNG's with Median Cut Posterizer (posterize -d -Q 100; maximum quality) which makes PNG's more compressible and save 2-3X more kBs with almost none visual difference. However, keep in mind it's lossy optimization.
  • Updated ApkTool v2 beta 7 to GitHub-2ef25fe5e2 latest version
  • Updated smali 2.0.1 to GitHub-263083faed latest version
  • Updated TruePNG to 0.4.0.9
  • Replaced PNGZopfli with ZopfliPNG which is better tool.
  • Default GOptimize options are now in bin\.DefaultGO file for easier editing
  • -zo option is now default instead -zb; you can still use -zb, it does the same as -zo;
  • PNG Optimization code improvements
  • Java 1.7 or above required for -b and -e
  • Archives are RAR5 format and WinRAR5 is needed to extract.

2013-10-17 v1.27 beta 122013-10-01 v1.26
  • Fixed -t i.e. signing not working in v1.25
2013-09-30 v1.25
  • Introduced Smart Recompression, read extra help.
  • Improved removing debug info, no -s option needed unless you want to strictly force smali v1 or v2
  • Reduced passes when recompressing from 16 to 11, difference is less <1kB on 16MB apk but now recompressing is faster...
2013-09-26 v1.24
  • Added jpe and jfif extensions to search list when optimizing jpg's which now is: jpg, jpeg, jpe, jfif.
  • Found and FIXED bug where files with no extension were not recompressed on -r option
  • ReWorked some compression code for easier reading and editing
  • Paths containing '!' (exclamation mark) will no longer be problem for script.
  • Minor code improvements...
  • You can now write -zo instead -zb if you like, it's easier for me =)
  • Updated smali v2 to 2.0b6 which can now remove debug info from some *****y classes.dex which smali 1.4.2 and 2.0b5 couldn't.
2013-09-25 v1.23
  • Added -j option to optimize jpg images in apk using jpegoptim
    -j0 is lossless optimization and is recommended; it only strips unnecessary info from jpg (like which app is used to create it) and optimizes huffman coding
    If you want to lower jpg's size even more, use -j95 which will recompress jpg's (and optimize) that are unnecessary big and only perform lossless optimization on others.
    Every JPG compression guide agrees that compression level above 95 is pointless and creates unnecessary big jpg's.
    I also left you choice to choose compression level between [75-100]
  • Reworked code for APK recompressing for easier adding of file extensions/formats that should always be uncompressed
    Also added zip and lzma to that list
  • Improved reading Java bin path from bin/.JavaPATH
  • Removed "Packing PNG's" info line after optimizing pngs; don't worry, optimized png's are still packed in apk
2013-09-22 v1.22
  • Added -t option to sign apk with Android test certificate so you can install goptimized apk's (Java configuration required)
2013-09-13 v1.21
  • Further improved MT PNG optimization
  • Added -s2 option so you can try removing debugging info using smali/baksmali v2 beta if default v1.4.2 fails
  • ReWorked compression levels; Read Extra Help; -he or -hh option
  • Updated TruePNG to 0.4.0.8
  • Updated CygWin Tools
  • Lots of "can't remember right now" minor fixes
2013-08-15 v1.20
  • PNG optimization MultiThreading code optimized, should be ~30% faster now....
  • PNG optimization now runs with low priority so it does not interfere with other apps and can run in background (will not make flash player stutter anymore, and other apps lag), but it uses 100% CPU if you're not using it because of new MT code...
  • PNGZopfli code optimization
2013-07-12 v1.19
  • MultiThreading code optimizations
  • PNGZopfli updated to 1.2
    I contacted author of PNGZopfli and TruePNG (http://x128.ho.ua) about some multithreading bugs in PNGZopfli for which I had to use sort of hack to work... It's now fixed in 1.2 and should be faster a bit...
  • Multiple ManualGO shells can be launched now as temp folder is named as apk...
  • Other minor fixes
2013-07-10 v1.17
  • NEW Feature: Removal of debug data from classes.dex using baksmali/smali; to use -b option you need to have JAVA installed and java bin path saved in /bin/.JavaPATH which is usually C:\Program Files\Java\jre[version number]\bin
    Script should be failsafe, i.e. revert on default classes.dex if baksmali/smali outputs any error
    You need to specify your roms API level for debug data removal. If you don't know it, use -b14. API LIST
  • NEW default options are: -m4 -a0 -d5 -l5
    Switched -l and -k option as it seems more logical to use -l for libraries recompression and -k for keep only architecture...
    Default options can be changed in /bin/.GOptimize file
  • NEW feature: PNGZopfli; use PNGZopfli instead PNGout in PNG optimizing chain with -zz option to save few more kB at cost ~20% more time; use both PNGout + PNGZopfli with -zb option for maximum kB savings on PNG optimizing at cost of extra ~20% more time needed for optimization
  • MultiThreading extended up to 16
  • TruePNG binary updated to 4.0.0.6
  • Lots of code optimization

2013-07-06 v1.15
  • Updated list of files that should always stay uncompressed for recompress option: png, jpg, jpeg, gif, wav, mp2, mp3, ogg, aac, mpg, mpeg, mid, midi, smf, jet, rtttl, imy, xmf, mp4, m4a, m4v, 3gp, 3gpp, 3g2, 3gpp2, amr, awb, wma, wmv.
2013-07-06 v1.14
  • NEW: MultiThreaded PNG optimization, made it faster x2-8 times dependable on how many cores your cpu have
  • NEW Features: Separate compression level for resources.arsc, classes.dex and libraries
  • New default options are "-m2 -a0 -d5 -l5" to use 2 threads for png optimization and recompress dex and libs with CL5 to make smaller apk as dex and libs are never accessed from apk, they are extracted on installation
  • In v1.14 default behaviour can be changed in /bin/.GOptimize
2013-06-21 v1.13
  • NEW Feature: Remove libraries not needed by your phone architecture... Why should you keep libraries for other architectures?
    Example: Tapatalk_4.0.14.apk; By removing libraries not for LT18i (armeabi-v7a) APK size is reduced from 10.6MB to 7.88MB; and by further optimizing PNG's APK size is reduced to 7.49MB. That is 3.11MB of unnecessary data...
  • FIX: APK's were getting mis-flagged as corrupted on recompression
2013-06-04 v1.12
  • APK's containing zip comments were mis-flagged as corrupted after optimization
  • Script displays a message when no resources.arsc detected...
2013-05-30 v1.11
  • Script will skip PNG's with corrupted header (or invalid ones)...found in UHD 3.1 beta UxpNxtLockScreen.apk->default_wallpaper.png
2013-05-29 v1.10
  • Saved size on PNG Optimization is now better and correctly calculated
    (On previous versions, saved size displayed was usually smaller than correct one and sometimes it displayed 0 when few kBs were saved)
  • Script now displays also percentage saved on PNG's
  • Added check for APK file to be correct type (ZIP)
  • Added check for APK to contain all files after optimization
  • BATCH scripts can now be run as administrator
  • FIXED: Stumbled upon error when GOptimizing eBay app, for some reason if not run as admin, some files were extracted with permission 000 which caused APK to miss some files
  • MISC Tweaks and Code optimization
2013-05-19 v1.04
  • "goptimize.sh *.apk" now works and optimizes all apk's in current directory
  • Treats files case-insensitive so ".PNG"'s also get optimized
  • Minor fixes and code rearrangement
2013-05-18
  • Made MiniCygwin_GOptimize_v1.02.7z which already contains all binaries and Cygwin tools. Just run GOptimize.cmd...
 
Last edited:

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
Latest Viber Test:
Code:
$ goptimize -j75 -pczo -d6 -b16 -s2 -l6 -k2 -e 'id' -Ei 'Viber v4.2.0.1733.apk'

[+] GOptimizing: <[ Viber v4.2.0.1733.apk ]>
 |- Cleaning resources of unneeded languages...
 |  |- Detected required languages...: de (id)
 |  |- Removing unneeded languages...: Success!
 |  |- Attempting to assemble APK....: Success!
 |  +- Integrating required strings..: Success!
 |- Extracting APK...
 |- Optimized PNG's: 100% | Saved: 2458 kB (46%)
 |- Optimized JPG's: 100% | Saved: 172 kB (42%)
 |- Removing debug info with smali v2.0.3-2d8cbfe6: Success!
 |- Recompressing classes.dex with CL(6)
 |- Recompressing libraries with CL(6)
 |- Removing libraries for: armeabi, x86
 |  + Keeping for: [armeabi-v7a]
 +- Zipaligning APK...

19.08 MB (19542KB) => 9.33 MB (9558KB)

Note: You need to preserve 'id' language when goptimizing Viber...
 
Last edited:
P

Phillip Wu

Guest
Woah , this deserve more attention . it's a great stuff. Thank for this .

Another combination : Odex + GOptimze = Amazing speed :good:
 

ct_moi

Senior Member
Jar files

Hi,

Thanks for the great tool, I've started playing yesterday with it and all is ok.
I've a question about *.jar files in system/framework to remove debug data from classes.dex.
I just try with framework.jar, rename it to framework.apk and it work.
It reduce the size from 4.24 to 3.30 Mo.
Push it tho the phone and it seems be ok.
Can I do that ?
For all jar files ?

Thanks - Eric
 
  • Like
Reactions: skinbark

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
Hi,

Thanks for the great tool, I've started playing yesterday with it and all is ok.
I've a question about *.jar files in system/framework to remove debug data from classes.dex.
I just try with framework.jar, rename it to framework.apk and it work.
It reduce the size from 4.24 to 3.30 Mo.
Push it tho the phone and it seems be ok.
Can I do that ?
For all jar files ?

Thanks - Eric

As I wrote it's just to remove debug info, recompress classes.dex at -d5.

You can as long it's deodexed...

What script does for removing debug info is that it de-compiles classes.dex without debug info with baksmali and re-compiles it back with smali...
If there were none errors in the process it puts new classes.dex in apk (or jar file in your case)...
In early script version I was testing only for extension ".apk", later I added test with 7zip to check if file is zip compatible file but didn't remove the limit for .apk extension....

I will look into it for next update, maybe in a week... For incoming update I already improved multithreading for PNG optimization a bit and I reworked compression levels; as before I used 7zip compression levels which didn't differ much (1,2,3 gave same compression) because I always used 16 passes in compression which does not impact decompression, just maxes compression (and makes it slower).
New compression levels will differ in fast bytes.
Level 1 will use 4 fast bytes, L2 8fb, L3 16fb, L4 32fb, L5 64fb, L6 128fb...
An you will be able to specify custom fb (in range 3-258) like "-afb4" for using 4 fast bytes for compressing resources.arsc; "-a4" will use 32 fast bytes...
Apks with resources.arsc in size over 1024kB give nice results and start faster for me when compressed with "-a1" aka "-afb4"...

More INFO on 7zip Deflate compression levels...
 

ct_moi

Senior Member
Ok I make it for all the framework directory (jar and apk) and it's working great.
I've make also some apk in system, the bigger.
I try to make me a rom clean with only 1 language.
Next step will be to reduce size for unused drawable resolution.

Thanks - Eric
 

methuselah

Senior Member
Aug 25, 2011
3,992
2,173
Hey can i flash this on my htc wildfire buzz with 2.3.7 rom?? This phone have very slow CPU and moreover got no gpu

Sent from my HTC Wildfire using xda app-developers app
 

Top Liked Posts

  • There are no posts matching your filters.
  • 55
    GOptimize v1.44 (BASH script for CYGWIN)
    ...is a tool for optimizing PNG's (and JPG's) in Android Applications and recompressing its files.​

    Help and Extra Help:
    Code:
    $ goptimize -he
    
    #####################[ GOptimize v1.44 ]########################
    ---------------------------------------------------------------#
      usage: goptimize [options] *.apk                             #
    ################################################################
      GOptimize optimizes APK's with various tools .:. gu5t3r@XDA  #
    ################################################################
     OPTIONS:                                                      #
      -h   Show Help                                               #
      -he  Show Help + Extra Help (also accepts -hh)               #
      -p   Optimize PNG's                                          #
      -9   Optimize 9-patch (*.9.png) PNG's while optimizing PNG's #
      -m   [1-16] Multi-Threaded PNG optimization; forces -p       #
      -zz  Use ZopfliPNG instead PNGout (More info in Extra Help)  #
      -zo  Use both PngOut + ZopfliPNG for max PNG compression     #
      -q   Convert PNG's to 8-bit with PngQuant with minimum       #
           required quality [0-100]; -q0 to force conversion       #
      -j   Optimize JPG's with jpegoptim; [0] or [75-100]          #
      -e   [-|??] Clean resources of unneeded languages            #
      -a   Recompress resources.arsc with CL[0-6]                  #
      -d   Recompress classes.dex with CL[0-6]                     #
      -b   Remove debug info from classes.dex for API[1-21] with   #
           baksmali/smali; -d[0-6] required; -d5 recommended       #
      -s   [1,2] Force smali v1 or v2 when removing debug info     #
      -l   Recompress libraries with CL[0-6]                       #
      -r   Recompress APK with  CL[0-6]                            #
      -R   [+,-] Smart Recompression modes, read extra help...     #
      -k   Keep only libraries for architecture: 1 armeabi         #
                                                 2 armeabi-v7a     #
                                                 3 mips            #
                                                 4 mipso32         #
                                                 5 x86             #
      -t  Sign APK with Android test certificate                   #
    ################################################################
                             Extra Help                            #
    ---------------------------------------------------------------#
      PNG Optimization:                                            #
          PNG optimization is lossless and tools used for it are:  #
          TruePNG, PngOut, ZopfliPNG and DeflOpt.                  #
                                                                   #
      ZopfliPNG (-z option info):                                  #
          [z] Use ZopfliPNG instead PngOut for better compression  #
           and saving few more kBs at cost of ~20% longer process. #
          [o|b] Use both PngOut + ZopfliPNG for max compression    #
           at cost of extra ~20 longer process compared to [z]     #
                                                                   #
      Converting PNG's to 8-bit with PngQuant (-q option)          #
          Converts PNG's to 8-bit with minimum required quality    #
          [0-100]. If quality of converted png is lower than       #
          minimum set threshold original png will be preserved.    #
          -q0 to force conversion; -q100 will skip almost all png  #
          Advanced MIN-MAX thresholds can be used [0-100]-[85-100] #
          PngQuant defaults are -q 45-85; if max threshold not     #
          specified it is set to 100.                              #
                                                                   #
      JPG's optimization with jpegoptim                            #
          [0] is lossless optimization and recommended.            #
              It does not recompress jpg's, it just strips all     #
              unnecessary info and optimizes huffman coding.       #
          [75-100] optimizes and recompresses jpg's. Level 95 is   #
              recommended, it will recompress unnecessary big ones #
              and do lossless optimization on other jpg's.         #
                                                                   #
      Cleaning resources of unneeded languages with ApkTool v2:    #
          [-]  Remove all unneeded lang. from resources            #
          [??] Keep language with ?? language code                 #
               You can keep multiple languages: -e 'hr en de fr'   #
          [-Ei] Addon option, example "-e 'hr' -Ei" will try       #
                to remove strings that are not required from       #
                required languages except the ones you're keeping. #
                Result: even smaller 'resuorces.arsc'.             #
          If you're cleaning system apps you need to put framework #
          files (framework-res.apk, etc...) in framework directory #
          where apk is located, usually: "PlaceApksHere\framework" #
                                                                   #
      Compression Levels:                                          #
          Script always uses 10 passes for compression which       #
          guarantees maximum compression and does not impact       #
          decompression time. Script CL differ in fast bytes.      #
              CL(1) <=>   4 fb        CL(4) <=>  32 fb             #
              CL(2) <=>   8 fb        CL(5) <=>  64 fb             #
              CL(3) <=>  16 fb        CL(6) <=> 128 fb             #
          You can also enter custom fast bytes number to be used   #
          for compression by entering fb[3-258] instead CL.        #
          Examples:   -afb3   -dfb69   -lfb132   -rfb258           #
                                                                   #
      APK Recompression (-r option):                               #
          As of v1.25 script uses Smart Recompressing i.e. it      #
          will leave files uncompressed in GOptimized apk that     #
          were uncompressed in original apk which is the best way  #
          for recompressing.                                       #
          -R+ Script will use Smart Recompression plus it will     #
              never compress file formats from below list even if  #
              they were compressed in original apk.                #
          -R- Script will disable Smart Recompress and store       #
              file formats uncompressed only if they are on below  #
              list.                                                #
          Following Android Asset Packaging Tool rules following   #
          list of file formats:                                    #
           "jpg jpeg jpe jfif png gif wav mp2 mp3 ogg aac mpg      #
            mpeg mid midi smf jet rtttl imy xmf mp4 m4a m4v 3gp    #
            3gp 3gpp 3g2 3gpp2 amr awb wma wmv zip lzma xz 7z lua  #
            pxp resS gltxt geo apf zi_"                            #
          should never be compressed as they are already           #
          compressed formats or don't compress well.               #
          Most developers use this file formats for databases and  #
          compressing them would result with application errors.   #
                                                                   #
      APK signing with Android test certificate                    #
          Non system apk's and apk's you want to install after     #
          goptimization are needed to be signed. You need Java     #
          configured for signing.                                  #
          Alternative is to patch rom (core.jar) with              #
          Lucky Patcher not to verify signatures.                  #
                                                                   #
      Configure Java:                                              #
          To use -b or -e feature you need to enter java bin path  #
          in bin\.JavaPATH file which is usually                   #
          "C:\Program Files\Java\jre[version number]\bin"          #
                                                                   #
      GOptimize.cmd Default Options:                               #
          You can edit GOptimize.cmd default options in            #
          bin\.DefaultGO file. GOptimize.cmd default options are:  #
                       "goptimize -p -q50 -j0 -a0 -d6 -l6 *.apk;"  #
    ################################################################

    [+] Download: https://www.mediafire.com/folder/a2z9fpcr4131a

    ApkTool: https://www.mediafire.com/folder/7vv4unj5diiu2
    Smali (Baksmali): https://www.mediafire.com/folder/p4b4d31bzcuj0
    17
    Changelog:

    2016-04-03 v1.44
    • Alowed use of Android API 1-23 for smali (23 is A6.0 MM)
    • Updated smali to v2.1.1
    • Updated ApkTool to v2.1.0
    • Updated pngquant with newest libpng v1.6.21 to v2.6.0
    • Updated jpegoptim with libjpeg v9b to v1.44
    2014-12-22 v1.43
    • Don't optimize 9 patch png's by default as ApkTool can't read them and decompile apk after....
    • Alowed use of Android API 1-21 for smali...
    • Updated smali to 686cf35c8e9d7eedc5af5989671917719dfe320a (2014-11-07)
    • Updated ApkTool to 2bd1e595df7dd0743f972845bd5874e8db65cd95 (2014-12-18)
    • Updated pngquant with newest libpng v1.6.15 to v2.3.1 (cc39b47799a7ff2ef17b529f9415ff6e6b213b8f) (2014-12-12)
    • Updated jpegoptim with libjpeg v9a to v1.42 (c6fa01bd56e00b764560b5ad3e1436ef829279c0) (2014-12-22)
    2014-07-16 v1.42
    • Don't overreduce colors on 9-patch pngs...
    • Recompiled zopflipng with O3 and some other optimizations for 30% speedup...
    • AutoRepair APK's with bad header...
    • Updated pngquant to v2.3.0 (8d21a4563e)
    2014-06-26 v1.41
    • GOptimize now also optimizes 9-patch (*.9.png) png's; To disable optimizing of 9-patch pngs use -9 option...
    • Updated libpng to v1.6.12 and recompiled pngquant with it
    2014-06-19 v1.40
    • Updated ApkTool to 2.0.0-RC1-a7b06f161b91dfdf985a717e9713dff5c46688b7 https://github.com/iBotPeaches/Apktool/commits/master
    • Updated pngquant to 2.2.0-860f9fb80fceac2998242ed7c5327da480964d24 https://github.com/pornel/pngquant/commits/master
    • Fix: Removed need for tr.exe. (although I still put it in bin just in case =)
    • Removed posterize because its inferior to pngquant. (-c option is now -q0-100 aka -q0)
    • Improved -Ei option to remove non-required strings from required languages except the ones you want to keep. Works on YouTube now...
    2014-06-01 v1.39
    • Changed default action to "goptimize -p -q50 -j0 -a0 -d6 -l6 *.apk;" as pngquant is much better than posterizer and setting -q50 is actually pngquant quality 50-100 so it won't reduce colors more than once no matter how many times you apply it...
    • In v1.38 cleaning of unneeded languages no longer worked with newest ApkTool, so I needed to change my code to read from new ApkTool output and as I were doing it I rewrote code for required strings integration to work better...
    • Compiled with libpng-1.6.10 and lcsm-2.6 and updated pngquant to 2.2 git-917f5e796d9d96ce22af25808e49ff24e4190176
    • Updated jpegoptim to v1.4.1 git-33aabed13dc24e16292405b79a13305059ba453a
    • Updated ApkTool to 2.0.0-RC1-848f0d6b5fb195f73222177ee161e35e6a1e65a6
    2014-04-30 v1.38
    • Updated all Cygwin tools
    • Compiled with libpng-1.6.10 and lcsm-2.6 and updated pngquant to 2.2 git-636151dd8e
    • Updated jpegoptim to git--e9dc8ef069
    • Updated zopflipng to zopfli-Hello71-e7778ddedb with bunch of fixes
    • Some script improvements...
    2014-04-09 v1.37
    • Added ability to specify advanced MIN-MAX thresholds when using pngquant; it's defaults are -q 45-85
    2014-04-09 v1.36
    • Added converting pngs's to 8-bit using PngQuant; -q [0-100] option
    • Updated smali v2 & ApkTool v2
    • smali v2 is now used as default instead v1
    2014-03-14 v1.35
    • Updated smali2: 2014-02-02 smali 2.0.3-2d8cbfe6.7z
    • Updated ApkTool v2 to 2014-03-09 ApkTool-GitHub-1e3b66f9be
    • Some layout folders were not removed when cleaning languages on newer apps
    • GOptimize now displays which version of ApkTool is used for cleaning
    2014-01-20 v1.34.02
    • Updated smali2 & baksmali2 to 2014-01-18 smali 2.0.3-4357de47
    • Updated ApkTool v2 to 2014-01-19 ApkTool-GitHub-a91e87bb04
    2013-12-14 v1.34.01
    • Updated smali2 & baksmali2 to GitHub-eae0b0edbf
    • Updated ApkTool v2 to beta 8 GitHub-d5d03fe1e4
    2013-11-27 v1.34
    • Fixed Bug where using a combination of -p, -j and -r options without -R would cause all files to be stored in apk without compression
    • Updated ApkTool v2 to beta 8 GitHub-a1ca5019d8
    2013-11-17 v1.33
    • Default options changed to "goptimize -p -j0 -a0 -d5 -l5 *.apk;" because now it auto detects number of CPU cores for PNG optimization. -m option no longer needed.
      You can also use shortcut -pczo for maximum png optimization instead -p -c -zo
    • NEW FEATURE: When cleaning unneeded languages use -Ei option to try to integrate only required strings from required languages to public strings to make even smaller resources.arsc; example "goptimize -e- -Ei *.apk"
      -Ea is alternative apk repacking on cleaning unneeded languages if apk does not work after; you can use both -Eai; -Eia does the same...
    • Updated ApkTool v2 to 2.0.0-Beta8-d2fc74d984 (GitHub)
    • Updated smali v2 to v2.0.2
    • Added defluff to PNG optimization chain for maximum PNG structure optimization
    • Code improvements and cleanup...
    2013-10-30 v1.32
    • FIXED Bug in Cleaning languages where optimizing multiple apps would cause required languages to accumulate i.e. detected required languages from above apk would not be removed from below/latter apks because I forgot to reset variables (or make them local).
      Thanks @ct_moi for detection =)
    2013-10-29 v1.31
    • Added some code to avoid where Median Cut Posterizer could make some small (<8kB) png's bigger than original.
      I was GOptimizing JEFIT with -czo and freaked out when PNG Savings went -100kB, so I added some code to avoid that =)
    • Updated TruePNG binary to v0.4.1.1
    2013-10-26 v1.30
    • Cleaning of unneeded languages works fine as long as ApkTool is able to rebuild apk; only problematic app which gets corrupted is GMail
      Known language codes: af am ar be bg bn ca cs da de el en es et fa fi fr gu hi hr hu id in it iw ja kn ko lt lv ml mr ms nb nl pa pl pt ro ru sk sl sr sv ta te th tl tr uk vi zh zu
    • NEW Feature: -c; Pre-process PNG's with Median Cut Posterizer (posterize -d -Q 100; maximum quality) which makes PNG's more compressible and save 2-3X more kBs with almost none visual difference. However, keep in mind it's lossy optimization.
    • Updated ApkTool v2 beta 7 to GitHub-2ef25fe5e2 latest version
    • Updated smali 2.0.1 to GitHub-263083faed latest version
    • Updated TruePNG to 0.4.0.9
    • Replaced PNGZopfli with ZopfliPNG which is better tool.
    • Default GOptimize options are now in bin\.DefaultGO file for easier editing
    • -zo option is now default instead -zb; you can still use -zb, it does the same as -zo;
    • PNG Optimization code improvements
    • Java 1.7 or above required for -b and -e
    • Archives are RAR5 format and WinRAR5 is needed to extract.

    2013-10-17 v1.27 beta 122013-10-01 v1.26
    • Fixed -t i.e. signing not working in v1.25
    2013-09-30 v1.25
    • Introduced Smart Recompression, read extra help.
    • Improved removing debug info, no -s option needed unless you want to strictly force smali v1 or v2
    • Reduced passes when recompressing from 16 to 11, difference is less <1kB on 16MB apk but now recompressing is faster...
    2013-09-26 v1.24
    • Added jpe and jfif extensions to search list when optimizing jpg's which now is: jpg, jpeg, jpe, jfif.
    • Found and FIXED bug where files with no extension were not recompressed on -r option
    • ReWorked some compression code for easier reading and editing
    • Paths containing '!' (exclamation mark) will no longer be problem for script.
    • Minor code improvements...
    • You can now write -zo instead -zb if you like, it's easier for me =)
    • Updated smali v2 to 2.0b6 which can now remove debug info from some *****y classes.dex which smali 1.4.2 and 2.0b5 couldn't.
    2013-09-25 v1.23
    • Added -j option to optimize jpg images in apk using jpegoptim
      -j0 is lossless optimization and is recommended; it only strips unnecessary info from jpg (like which app is used to create it) and optimizes huffman coding
      If you want to lower jpg's size even more, use -j95 which will recompress jpg's (and optimize) that are unnecessary big and only perform lossless optimization on others.
      Every JPG compression guide agrees that compression level above 95 is pointless and creates unnecessary big jpg's.
      I also left you choice to choose compression level between [75-100]
    • Reworked code for APK recompressing for easier adding of file extensions/formats that should always be uncompressed
      Also added zip and lzma to that list
    • Improved reading Java bin path from bin/.JavaPATH
    • Removed "Packing PNG's" info line after optimizing pngs; don't worry, optimized png's are still packed in apk
    2013-09-22 v1.22
    • Added -t option to sign apk with Android test certificate so you can install goptimized apk's (Java configuration required)
    2013-09-13 v1.21
    • Further improved MT PNG optimization
    • Added -s2 option so you can try removing debugging info using smali/baksmali v2 beta if default v1.4.2 fails
    • ReWorked compression levels; Read Extra Help; -he or -hh option
    • Updated TruePNG to 0.4.0.8
    • Updated CygWin Tools
    • Lots of "can't remember right now" minor fixes
    2013-08-15 v1.20
    • PNG optimization MultiThreading code optimized, should be ~30% faster now....
    • PNG optimization now runs with low priority so it does not interfere with other apps and can run in background (will not make flash player stutter anymore, and other apps lag), but it uses 100% CPU if you're not using it because of new MT code...
    • PNGZopfli code optimization
    2013-07-12 v1.19
    • MultiThreading code optimizations
    • PNGZopfli updated to 1.2
      I contacted author of PNGZopfli and TruePNG (http://x128.ho.ua) about some multithreading bugs in PNGZopfli for which I had to use sort of hack to work... It's now fixed in 1.2 and should be faster a bit...
    • Multiple ManualGO shells can be launched now as temp folder is named as apk...
    • Other minor fixes
    2013-07-10 v1.17
    • NEW Feature: Removal of debug data from classes.dex using baksmali/smali; to use -b option you need to have JAVA installed and java bin path saved in /bin/.JavaPATH which is usually C:\Program Files\Java\jre[version number]\bin
      Script should be failsafe, i.e. revert on default classes.dex if baksmali/smali outputs any error
      You need to specify your roms API level for debug data removal. If you don't know it, use -b14. API LIST
    • NEW default options are: -m4 -a0 -d5 -l5
      Switched -l and -k option as it seems more logical to use -l for libraries recompression and -k for keep only architecture...
      Default options can be changed in /bin/.GOptimize file
    • NEW feature: PNGZopfli; use PNGZopfli instead PNGout in PNG optimizing chain with -zz option to save few more kB at cost ~20% more time; use both PNGout + PNGZopfli with -zb option for maximum kB savings on PNG optimizing at cost of extra ~20% more time needed for optimization
    • MultiThreading extended up to 16
    • TruePNG binary updated to 4.0.0.6
    • Lots of code optimization

    2013-07-06 v1.15
    • Updated list of files that should always stay uncompressed for recompress option: png, jpg, jpeg, gif, wav, mp2, mp3, ogg, aac, mpg, mpeg, mid, midi, smf, jet, rtttl, imy, xmf, mp4, m4a, m4v, 3gp, 3gpp, 3g2, 3gpp2, amr, awb, wma, wmv.
    2013-07-06 v1.14
    • NEW: MultiThreaded PNG optimization, made it faster x2-8 times dependable on how many cores your cpu have
    • NEW Features: Separate compression level for resources.arsc, classes.dex and libraries
    • New default options are "-m2 -a0 -d5 -l5" to use 2 threads for png optimization and recompress dex and libs with CL5 to make smaller apk as dex and libs are never accessed from apk, they are extracted on installation
    • In v1.14 default behaviour can be changed in /bin/.GOptimize
    2013-06-21 v1.13
    • NEW Feature: Remove libraries not needed by your phone architecture... Why should you keep libraries for other architectures?
      Example: Tapatalk_4.0.14.apk; By removing libraries not for LT18i (armeabi-v7a) APK size is reduced from 10.6MB to 7.88MB; and by further optimizing PNG's APK size is reduced to 7.49MB. That is 3.11MB of unnecessary data...
    • FIX: APK's were getting mis-flagged as corrupted on recompression
    2013-06-04 v1.12
    • APK's containing zip comments were mis-flagged as corrupted after optimization
    • Script displays a message when no resources.arsc detected...
    2013-05-30 v1.11
    • Script will skip PNG's with corrupted header (or invalid ones)...found in UHD 3.1 beta UxpNxtLockScreen.apk->default_wallpaper.png
    2013-05-29 v1.10
    • Saved size on PNG Optimization is now better and correctly calculated
      (On previous versions, saved size displayed was usually smaller than correct one and sometimes it displayed 0 when few kBs were saved)
    • Script now displays also percentage saved on PNG's
    • Added check for APK file to be correct type (ZIP)
    • Added check for APK to contain all files after optimization
    • BATCH scripts can now be run as administrator
    • FIXED: Stumbled upon error when GOptimizing eBay app, for some reason if not run as admin, some files were extracted with permission 000 which caused APK to miss some files
    • MISC Tweaks and Code optimization
    2013-05-19 v1.04
    • "goptimize.sh *.apk" now works and optimizes all apk's in current directory
    • Treats files case-insensitive so ".PNG"'s also get optimized
    • Minor fixes and code rearrangement
    2013-05-18
    • Made MiniCygwin_GOptimize_v1.02.7z which already contains all binaries and Cygwin tools. Just run GOptimize.cmd...
    8
    Changelog:

    2016-04-03 v1.44
    • Alowed use of Android API 1-23 for smali (23 is A6.0 MM)
    • Updated smali to v2.1.1
    • Updated ApkTool to v2.1.0
    • Updated pngquant with newest libpng v1.6.21 to v2.6.0
    • Updated jpegoptim with libjpeg v9b to v1.44

    Tested with latest Google Play Store v6.3.16.B ( 14.7MB --> 6.41MB )
    Code:
    goptimize -p -9 -zo -q0 -j0 -e- -Ei -d6 -b22 GPS.apk
    7
    Latest Viber Test:
    Code:
    $ goptimize -j75 -pczo -d6 -b16 -s2 -l6 -k2 -e 'id' -Ei 'Viber v4.2.0.1733.apk'
    
    [+] GOptimizing: <[ Viber v4.2.0.1733.apk ]>
     |- Cleaning resources of unneeded languages...
     |  |- Detected required languages...: de (id)
     |  |- Removing unneeded languages...: Success!
     |  |- Attempting to assemble APK....: Success!
     |  +- Integrating required strings..: Success!
     |- Extracting APK...
     |- Optimized PNG's: 100% | Saved: 2458 kB (46%)
     |- Optimized JPG's: 100% | Saved: 172 kB (42%)
     |- Removing debug info with smali v2.0.3-2d8cbfe6: Success!
     |- Recompressing classes.dex with CL(6)
     |- Recompressing libraries with CL(6)
     |- Removing libraries for: armeabi, x86
     |  + Keeping for: [armeabi-v7a]
     +- Zipaligning APK...

    19.08 MB (19542KB) => 9.33 MB (9558KB)

    Note: You need to preserve 'id' language when goptimizing Viber...
    7
    Changelog:

    2014-01-20 v1.34.02
    • Updated smali2 & baksmali2 to 2014-01-18 smali 2.0.3-4357de47
    • Updated ApkTool v2 to 2014-01-19 ApkTool-GitHub-a91e87bb04

    Updated smali and apktool...

    You can also download and update smali and apktool manually as I compile them from alternate link...
    (Just replace smali2.jar, baksmali2.jar and apktool.jar in bin folder)

    http://d-h.st/users/gu5t3r/?fld_id=30675

    http://d-h.st/users/gu5t3r/?fld_id=30132

    In future, as I will be compiling smali and apktool for myself I will upload them to above links...
    You can see your current version of tools in ManualGO with:
    Code:
    smali2 -v
    baksmali2 -v
    apktool -version