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

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
0
Great tool thanks! I've found many apk's with thumbs.db file hidden in it. If you use jpegtran on the jpg files, you may also reduce a lot of size.
Well, it's jpegtran -optimize feature looks promising for reducing few more kBs
Thanks =)
Will try on an apk and see if android has problem with optimized jpgs...
 

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
0
Thank you

In case of a user app should I use -b with the number of my phone API level or with the highest API level number for which the app is written?
I use API Level of my Rom, 15 for ICS...
I made removing debugging info Fail-Safe, if there are any errors in the process script will inform you that removing debug info is failed and revert to original classes.dex...
Didn't test lower API Levels...
 

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
0
Coming soon in v1.23 =)
Code:
$ goptimize -m4 -zb -j0 'Clean Master (Cleaner) v3.8.1.apk'

[+] GOptimizing: <[ Clean Master (Cleaner) v3.8.1.apk ]>
 |- Extracting APK...
 |- Optimized PNG's: 100% | Saved: 123 kB (19%)
 |- Optimized JPG's: 100% | Saved: 31 kB (6%)
 +- Zipaligning APK...
 
Last edited:

Madaditya

Senior Member
Jul 30, 2012
985
1,053
0
Pune
referany.com
I get this error

Code:
##########[ MiniCygwin GOptimize v1.22 ]###########

[i] Put APK's in "PlaceApksHere"
    and press any key to start...


[+] GOptimizing: <[ Facebook.apk ]>
 |- Extracting APK...
 |- Optimized PNG's: 100% | Saved: 532 kB (18%)
 |- Packing PNG's in APK...
 |- Storing resources.arsc uncompressed
 |- Removing debugging info from classes.dex using smali
[w] Failed Removing debugging info...
 |- Recompressing classes.dex with CL(5)
 |- Recompressing libraries with CL(5)
 |- Signing APK with Android test certificate
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:393)
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:396)
java.lang.NullPointerException
        at java.io.ByteArrayInputStream.<init>(Unknown Source)
        at s.Sign.readPublicKey(Sign.java:78)
        at s.Sign.sign(Sign.java:435)
        at s.Sign.main(Sign.java:532)
 +- Zipaligning APK...
Unable to open 'Facebook.apk' as zip archive
mv: cannot stat `Facebook.apk.zipa': No such file or directory


[i] Press any key to exit...
Is it Java config error? i did configure it properly

also tried removing '-b'(remove debugging) option but some error with testkey
 
Last edited:

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
0
I get this error

Code:
##########[ MiniCygwin GOptimize v1.22 ]###########

[i] Put APK's in "PlaceApksHere"
    and press any key to start...


[+] GOptimizing: <[ Facebook.apk ]>
 |- Extracting APK...
 |- Optimized PNG's: 100% | Saved: 532 kB (18%)
 |- Packing PNG's in APK...
 |- Storing resources.arsc uncompressed
 |- Removing debugging info from classes.dex using smali
[w] Failed Removing debugging info...
 |- Recompressing classes.dex with CL(5)
 |- Recompressing libraries with CL(5)
 |- Signing APK with Android test certificate
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:393)
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:396)
java.lang.NullPointerException
        at java.io.ByteArrayInputStream.<init>(Unknown Source)
        at s.Sign.readPublicKey(Sign.java:78)
        at s.Sign.sign(Sign.java:435)
        at s.Sign.main(Sign.java:532)
 +- Zipaligning APK...
Unable to open 'Facebook.apk' as zip archive
mv: cannot stat `Facebook.apk.zipa': No such file or directory


[i] Press any key to exit...
Is it Java config error? i did configure it properly

also tried removing '-b'(remove debugging) option but some error with testkey
Try removing new line character from bin/.JavaPATH if you have it, if you still get error then Java version is to low or Java is incorrectly installed.
Try installing latest Java 1.7, you will also have to put new Java bin path in bin/.JavaPATH if you had 1.6 or lower before...
 

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
0
Just checked if there is new line after Java bin path it does not recognize Java at all
Edited script to read only first line if there are multiple lines in bin/.JavaPATH

Will be fixed in v1.23, for now if you have new line in .JavaPATH remove it

But, I still think your problem is bad Java installation or old Java version

You should always edit GOptimize files with Notepad2 or Notepad++ because windows notepad does not recognize unix files correctly...
 

Madaditya

Senior Member
Jul 30, 2012
985
1,053
0
Pune
referany.com
Just checked if there is new line after Java bin path it does not recognize Java at all
Edited script to read only first line if there are multiple lines in bin/.JavaPATH

Will be fixed in v1.23, for now if you have new line in .JavaPATH remove it

But, I still think your problem is bad Java installation or old Java version

You should always edit GOptimize files with Notepad2 or Notepad++ because windows notepad does not recognize unix files correctly...
i dont have a newline in .Java PATH and i do use Notepad++

this' what my java folder looks like

Untitled.jpg

I Gave path as

Code:
C:\Program Files\Java\jre7\bin
and also tried
Code:
C:\Program Files\Java\jre6\bin
manualGo.cmd detects 'which java' and gives the right path though!

BUt have the Same Problem!
 
Last edited:

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
0
i dont have a newline in .Java PATH and i do use Notepad++

this' what my java folder looks like

View attachment 2282749

I Gave path as

Code:
C:\Program Files\Java\jre7\bin
and also tried
Code:
C:\Program Files\Java\jre6\bin
manualGo.cmd detects 'which java' and gives the right path though!

BUt have the Same Problem!
Can you enter in ManualGO

Code:
sign
and
Code:
java -jar "$(cygpath -wal "/bin/sign.jar")"
and
Code:
cygpath -wal "/bin/sign.jar"
 

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
0
Changelog: 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

Code:
$ goptimize -j0 *.apk

[+] GOptimizing: <[ Clean Master (Cleaner) v3.8.1 build 30810406.apk ]>
 |- Extracting APK...
 |- Optimized JPG's: 100% | Saved: 31 kB (6%)
 +- Zipaligning APK...

$ goptimize -j95 *.apk

[+] GOptimizing: <[ Clean Master (Cleaner) v3.8.1 build 30810406.apk ]>
 |- Extracting APK...
 |- Optimized JPG's: 100% | Saved: 31 kB (6%)
 +- Zipaligning APK...

$ goptimize -j90 *.apk

[+] GOptimizing: <[ Clean Master (Cleaner) v3.8.1 build 30810406.apk ]>
 |- Extracting APK...
 |- Optimized JPG's: 100% | Saved: 44 kB (9%)
 +- Zipaligning APK...

$ goptimize -j85 *.apk

[+] GOptimizing: <[ Clean Master (Cleaner) v3.8.1 build 30810406.apk ]>
 |- Extracting APK...
 |- Optimized JPG's: 100% | Saved: 85 kB (17%)
 +- Zipaligning APK...
Code:
$ goptimize -j0 *.apk

[+] GOptimizing: <[ Facebook for Android v3.7 build 367848.apk ]>
 |- Extracting APK...
 |- Optimized JPG's: 100% | Saved: 10 kB (4%)
 +- Zipaligning APK...

$ goptimize -j95 *.apk

[+] GOptimizing: <[ Facebook for Android v3.7 build 367848.apk ]>
 |- Extracting APK...
 |- Optimized JPG's: 100% | Saved: 20 kB (7%)
 +- Zipaligning APK...

$ goptimize -j90 *.apk

[+] GOptimizing: <[ Facebook for Android v3.7 build 367848.apk ]>
 |- Extracting APK...
 |- Optimized JPG's: 100% | Saved: 56 kB (21%)
 +- Zipaligning APK...

$ goptimize -j85 *.apk

[+] GOptimizing: <[ Facebook for Android v3.7 build 367848.apk ]>
 |- Extracting APK...
 |- Optimized JPG's: 100% | Saved: 87 kB (33%)
 +- Zipaligning APK...
 

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
0
Hi gu5t3r, that was fast! Thank you very much for implementing, I will try it.
=) Only thing I forgot to add jpe and jfif extensions to jpg list (script now searches for jpg and jpeg)
but that shouldn't be problem as all apps i tried use jpg

Will be in v1.24 =)
 

Madaditya

Senior Member
Jul 30, 2012
985
1,053
0
Pune
referany.com
Can you enter in ManualGO

Code:
sign
and
Code:
java -jar "$(cygpath -wal "/bin/sign.jar")"
and
Code:
cygpath -wal "/bin/sign.jar"
And this' is what i get!
:(
Code:
[email protected] /PlaceApksHere
$ sign
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:393)
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:396)
Usage: java -jar sign.jar my_1.apk [my_2.apk ...] [--override]

[email protected] /PlaceApksHere
$ java -jar "$(cygpath -wal "/bin/sign.jar")"
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:393)
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:396)
Usage: java -jar sign.jar my_1.apk [my_2.apk ...] [--override]

[email protected] /PlaceApksHere
$ cygpath -wal "/bin/sign.jar"
E:\Sonu\Android-Root\Tools\Apk EDits!\Go Optimizer\MiniCygwin_GOptimize_v1.22\bi
n\sign.jar

[email protected] /PlaceApksHere
$
Edit:Post #57 Worked!

Just Placed 'Goptimizer' with its parent folder and all works!
 
Last edited:

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
0
And this' is what i get!
:(
Code:
[email protected] /PlaceApksHere
$ sign
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:393)
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:396)
Usage: java -jar sign.jar my_1.apk [my_2.apk ...] [--override]

[email protected] /PlaceApksHere
$ java -jar "$(cygpath -wal "/bin/sign.jar")"
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:393)
java.lang.NullPointerException
        at s.IOUtils.copyLarge(IOUtils.java:61)
        at s.IOUtils.copy(IOUtils.java:49)
        at s.IOUtils.toByteArray(IOUtils.java:39)
        at s.Sign.<clinit>(Sign.java:396)
Usage: java -jar sign.jar my_1.apk [my_2.apk ...] [--override]

[email protected] /PlaceApksHere
$ cygpath -wal "/bin/sign.jar"
E:\Sonu\Android-Root\Tools\Apk EDits!\Go Optimizer\MiniCygwin_GOptimize_v1.22\bi
n\sign.jar

[email protected] /PlaceApksHere
$
Edit:Post #57 Worked!

Just Placed 'Goptimizer' with its parent folder and all works!
Problem is 100% in
Code:
!
in PATH...
 

gu5t3r

Senior Member
May 30, 2012
1,610
1,516
0
Changelog: 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 bitchy classes.dex which smali 1.4.2 and 2.0b5 couldn't.
 
Last edited:
  • Like
Reactions: ct_moi