Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Redex - A bytecode optimizer for Android apps

Redex - A bytecode optimizer for Android apps

Redex is a bytecode optimizer for Android apps developed by Facebook, Inc.

APK size matters to all users, especially for users in developing countries. Redex optimizes the .dex files inside your raw APK or ProGuarded APK. This may reduce your APK size but also may fasten your app itself by optimizing the bytecode inside .dex files, all for free!

facebook/redex: A bytecode optimizer for Android apps
https://github.com/facebook/redex

Redex
http://fbredex.com

Optimizing Android bytecode with ReDex | Engineering Blog | Facebook Code
https://code.facebook.com/posts/1480969635539475/optimizing-android-bytecode-with-redex

Tests don't setup correctly · Issue #177 · facebook/redex
https://github.com/facebook/redex/issues/177

Apk size diet // Speaker Deck
https://speakerdeck.com/konifar/apk-size-diet

Facebook、Androidアプリのバイトコードを最適化する「ReDex」をオープンソース化:CodeZine(コードジン)
https://codezine.jp/article/detail/9381

Shohei Kawano

October 26, 2016
Tweet

More Decks by Shohei Kawano

Other Decks in Programming

Transcript

  1. Redex • What is Redex? • Redex and ProGurad •

    How does Redex optimize .dex files • Sample output • Usage / Tips (for Mac) • Conclusion
  2. What is Redex? • Android bytecode (dex) optimizer • Read,

    analyze and optimize .dex files • Initial commit: 2016.03.25 / ˒: ~3100 • Originally developed by Facebook, Inc. http://fbredex.com
  3. What is Redex? • Android bytecode (dex) optimizer • Read,

    analyze and optimize .dex files • Initial commit: 2016.03.25 / ˒: ~3100 • Originally developed by Facebook, Inc. http://fbredex.com “An APK optimized by ReDex should be smaller and faster than its source.”
  4. Redex and ProGuard https://github.com/facebook/redex#how-does-this-compare-to-proguard • ProGuard optimizes .class files bytecode

    • ProGuard has more capabilities
 e.g. it can reduce unused method parameters • You may need to configure proguard- rules.pro ProGuard
  5. Redex and ProGuard https://github.com/facebook/redex#how-does-this-compare-to-proguard • Redex optimizes .dex files bytecode

    • Redex can inline source codes that ProGuard misses to inline • Redex cannot reduce unused method parameters • No rules required Redex
  6. How does Redex optimize .dex files? https://code.facebook.com/posts/1480969635539475/optimizing-android-bytecode-with-redex • Minification •

    Reducing and minimizing strings without changing functionality • Inlining methods • Dead code elimination • etc.
  7. http://fbredex.com $ brew install autoconf automake libtool python3 $ brew

    install boost double-conversion gflags glog libevent jsoncpp Install Command Line Tools Install Dependent tools using Homebrew For “/usr/local must be writable!” error $ xcode-select —install Usage / Tips (for Mac) Tips! Maybe You need to confer appropriate permission: https://github.com/Homebrew/legacy-homebrew/issues/49895
  8. $ git clone https://github.com/facebook/redex.git
 $ cd redex http://fbredex.com Clone Redex

    repository Build ReDex(May take some time) $ autoreconf -ivf && ./configure && make
 ReDex your APK $ redex path/to/your.apk -o path/to/output.apk
 Usage / Tips (for Mac)
  9. $ ANDROID_SDK=path_to_android_sdk redex ./target.apk -o ./output.apk http://fbredex.com For “Couldn't find

    zipalign. See README.md..” Error Usage / Tips (for Mac) Execute the command with Android SDK path specified: Tips! Testing $ ./test/setup.sh $ cd test $ make check /Applications/Xcode.app/Contents/Developer/usr/bin/make libgtest_main.la make[2]: *** No rule to make target `gtest-1.7.0/src/ gtest-all.cc', needed by `gtest-1.7.0/src/ libgtest_main_la-gtest-all.lo'. Stop. make[1]: *** [check-am] Error 2 make: *** [check-recursive] Error 1 " https://github.com/facebook/redex/issues/177
  10. Conclusion • Trying to shrink APK size is quite important

    (Especially the apps for developing countries). • ProGuarding and Redexing your APK to reduce its size if possible. (Facebook does.) • Maybe integrating with CI in the future?