Slide 1

Slide 1 text

͔Θͷ@shaunkawano A bytecode optimizer for Android apps Redex

Slide 2

Slide 2 text

͔Θͷ@shaunkawano A bytecode optimizer for Android apps Redex http://fbredex.com

Slide 3

Slide 3 text

Redex • What is Redex? • Redex and ProGurad • How does Redex optimize .dex files • Sample output • Usage / Tips (for Mac) • Conclusion

Slide 4

Slide 4 text

What is Redex?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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.”

Slide 7

Slide 7 text

Redex and ProGuard

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

How does Redex optimize .dex files?

Slide 11

Slide 11 text

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.

Slide 12

Slide 12 text

Sample output

Slide 13

Slide 13 text

Sample output

Slide 14

Slide 14 text

Sample Output APK SIZE: 4.6MB → 4.3MB

Slide 15

Slide 15 text

Usage / Tips (for Mac)

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

$ 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)

Slide 18

Slide 18 text

$ 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

Slide 19

Slide 19 text

Conclusion

Slide 20

Slide 20 text

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?

Slide 21

Slide 21 text

fin. ͔Θͷ@shaunkawano A bytecode optimizer for Android apps Redex