Uglyfier for Android


Source link: https://github.com/PGSSoft/uglyfier

Uglyfier for Android

Gradle script for downsizing graphical assets in development builds

Problem

Usually you don't care how big the deployed APK is. However, if you are using metered connection and remote ADB, it would be good idea to build possibly smallest APK file.

Solution

Uglyfier for Android is a gradle script which will shrink all image resources in your application during build. It will look ugly, but image files will be 10 times smaller. Ninepatch (9-patch) PNGs are fully supported, with transparency preserved!

Installation

  1. Install ImageMagick
  2. Download uglyfy.gradle and save it to application directory (where build.gradle live)
  3. Create new buildType, i.e. "uglyfied". You can define it to inherit existing one:
    buildTypes {
    
      debug {
    
    debuggable true
      
    }
    
    uglyfied.initWith(buildTypes.debug)
      uglyfied{
    
    }
    
  4. Add following snippet to your build.gradle, adjusting all three variables.
    ext {
    
      UglyfierSourceVariant
    
    = 'debug'
      // this is the source build type
      UglyfierDestinationVariant = 'uglyfied'  // this is the target, uglyfied build type
    
    // provide path to Imagemagick here
      // (or remove this line and set IMAGEMAGICK_EXECUTABLE environment variable
      UglyfierImagemagickPath = 'c:/Program Files/ImageMagick-7.0.1-10-portable-Q16-x86/magick.exe' //sample value for Windows
      //UglyfierImagemagickPath = '/usr/bin/convert' //sample value for Linux 
    }
     apply from: 'uglyfy.gradle'
     
  5. Try to build new "uglyfied" variant.

What will happen?

During build following events will take place:

  1. Image files (PNG, JPG, JPEG) from "main" resource directory will be copied to "uglyfied" resource directory, then downsized.
  2. Image files from source variant (i.e. "debug") will be also copied to "uglyfied" resource directory, then downsized.
  3. Any extra resource files from source variant (i.e. "debug") will be also copied to "uglyfied" resource directory.

How the downsizing works?

JPEG files are heavily recompressed, with target quality=5. Compression artifacts are expected.

PNG files are downsized to 10% of size, then scaled back. Big pixel blocks are expected. Ninepatch (9-patch) files are fully supported, 1-pixel frame is preserved! (as well as transparency)

Files smaller than 5KB are skipped.

Results

We tested Uglyfier with our internal projects that contain many graphical assets and here are our results:

Normal image resources size Uglyfied image resources size Size reduction
18124 KB 3060 KB 83%
9258 KB 861 KB 91%

Below you can see what is the difference in application's assets quality with uglyfied and standard build:

Standard (top) / Uglyfied (bottom)

TODO

  • Better build event injection than clean.doLast
  • Re-uglyfying based on file modification time, not every time

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/PGSSoft/uglyfier.

License

The project is available as open source under the terms of the MIT License.

About

The project maintained by software development agency PGS Software. See our other open-source projects or contact us to develop your product.

Follow us


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes