Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ProGuard
Search
Edward Dale
August 31, 2017
Technology
1
470
ProGuard
An introduction to how ProGuard works.
Edward Dale
August 31, 2017
Tweet
Share
More Decks by Edward Dale
See All by Edward Dale
Write your own ProGuard
scompt
1
190
Screenshot your Entire App with Screengrab and Firebase
scompt
0
420
Screenshot your Entire App
scompt
1
1.9k
Reactive In-App Billing on Android
scompt
2
270
Fitness Motion Recognition with Android Wear
scompt
1
400
Android Apps with Mortar and Flow
scompt
7
1.6k
Functional Reactive Programming in the Mobile World
scompt
2
320
Other Decks in Technology
See All in Technology
なんで、私がAWS Heroに!? 〜社外の広い世界に一歩踏み出そう〜
minorun365
PRO
6
1.1k
AIを駆使したゲーム開発戦略: 新設AI組織の取り組み / sge-ai-strategy
cyberagentdevelopers
PRO
1
130
使えそうで使われないCloudHSM
maikamibayashi
0
170
急成長中のWINTICKETにおける品質と開発スピードと向き合ったQA戦略と今後の展望 / winticket-autify
cyberagentdevelopers
PRO
1
160
【若手エンジニア応援LT会】AWS Security Hubの活用に苦労した話
kazushi_ohata
0
170
2024-10-30-reInventStandby_StudyGroup_Intro
shinichirokawano
1
630
ガチ勢によるPipeCD運用大全〜滑らかなCI/CDを添えて〜 / ai-pipecd-encyclopedia
cyberagentdevelopers
PRO
3
210
Datachain会社紹介資料(2024年11月) / Company Deck
datachain
3
16k
ガバメントクラウド先行事業中間報告を読み解く
sugiim
1
1.4k
最速最小からはじめるデータプロダクト / Data Product MVP
amaotone
5
740
一休.comレストランにおけるRustの活用
kymmt90
3
580
チームを主語にしてみる / Making "Team" the Subject
ar_tama
4
310
Featured
See All Featured
Embracing the Ebb and Flow
colly
84
4.4k
KATA
mclloyd
29
13k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
228
52k
Into the Great Unknown - MozCon
thekraken
31
1.5k
RailsConf 2023
tenderlove
29
880
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Teambox: Starting and Learning
jrom
132
8.7k
What's new in Ruby 2.0
geeforr
342
31k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
Transcript
ProGuard Edward Dale @scompt Freeletics https://www.freeletics.com August 31, 2017 ©
Edward Dale, 2017 1
Agenda • Overview • Steps • Problems • Future ©
Edward Dale, 2017 2
Purpose ProGuard is the most popular optimizer for Java bytecode.
It makes your Java and Android applications up to 90% smaller and up to 20% faster. ProGuard also provides minimal protection against reverse engineering by obfuscating the names of classes, fields and methods. — https://www.guardsquare.com/en/proguard © Edward Dale, 2017 3
Purpose ProGuard is the most popular optimizer for Java bytecode.
It makes your Java and Android applications up to 90% smaller and up to 20% faster. ProGuard also provides minimal protection against reverse engineering by obfuscating the names of classes, fields and methods. — https://www.guardsquare.com/en/proguard © Edward Dale, 2017 4
Highlights 1 • ProGuard is a command-line tool with an
optional graphical user interface. • ProGuard is easy to configure. A few intuitive command line options or a simple configuration file is all it takes. All available options are detailed in the user manual. 1 https://www.guardsquare.com/en/proguard © Edward Dale, 2017 5
Highlights 1 (continued) • ProGuard is fast. It processes small
Android applications and entire run-time libraries in seconds. • ProGuard is the default tool in development environments like Oracle’s Wireless Toolkit, NetBeans, EclipseME, Intel’s TXE SDK and Google’s Android SDK. 1 https://www.guardsquare.com/en/proguard © Edward Dale, 2017 6
Highlights (annotated) • ProGuard is easy to configure. A few
intuitive command line options or a simple configuration file is all it takes. All available options are detailed in the user manual. • ProGuard is fast. It processes small Android applications and entire run- time libraries in seconds. © Edward Dale, 2017 7
Steps start shrink end optimize obfuscate preverify © Edward Dale,
2017 8
Shrink Step • Enabled by default • Disabled with -dontshrink
• Removes all classes, methods, resources not reachable from from an entry point (seeds) • Dynamically referenced classes/methods need to be "kept" using -keep or -keepclasseswithmembers © Edward Dale, 2017 9
Example Class Diagram LoginActivity UserManager UserApi FeedActivity FeedApi OldUserManager OldUserApi
© Edward Dale, 2017 10
After Shrinking • No seeds LoginActivity UserManager UserApi FeedActivity FeedApi
OldUserManager OldUserApi © Edward Dale, 2017 11
After Shrinking • -keep MainActivity • -keep SecondActivity LoginActivity UserManager
UserApi FeedActivity FeedApi OldUserManager OldUserApi © Edward Dale, 2017 12
After Shrinking • -keep public class * extends android.app.Activity LoginActivity
UserManager UserApi FeedActivity FeedApi OldUserManager OldUserApi © Edward Dale, 2017 13
Keep Options -keep Specifies classes and class members (fields and
methods) to be preserved as entry points to your code. -keepclassmembers Specifies class members to be preserved, if their classes are preserved as well. -keepclasseswithmembers Specifies classes and class members to be preserved, on the condition that all of the specified class members are present. © Edward Dale, 2017 14
Optimize Step • Enabled by default • Disabled with -dontoptimize
• Performs lots of different bytecode-level optimizations to the code © Edward Dale, 2017 15
Optimize Step • -optimizationpasses declares how many times to optimize/shrink
• Freeletics does 5 passes © Edward Dale, 2017 16
Optimize Step • -optimizations can be used to disable specific
optimizations • Freeletics disables optimizations that cause problems on Android • More information in $ANDROID_HOME/tools/proguard/ proguard-android-optimize.txt © Edward Dale, 2017 17
Example Optimizations 2 • Marks methods as final, whenever possible.
• Removes unused method parameters. • Propagates the values of method parameters from method invocations to the invoked methods. • Propagates the values of method return values from methods to their invocations. • Inlines short methods. • Inlines methods that are only called once. 2 https://www.guardsquare.com/en/proguard/manual/optimizations © Edward Dale, 2017 18
Obfuscate Step • Enabled by default • Disabled with -dontobfuscate
• Classes and class members receive new short random names, except for the ones listed by the various -keep options • Internal attributes that are useful for debugging are removed © Edward Dale, 2017 19
After Obfuscation LoginActivity A B FeedActivity C OldUserManager OldUserApi ©
Edward Dale, 2017 20
Preverification Step • Enabled by default • Disabled with -dontpreverify
• When loading class files, the class loader performs some sophisticated verification of the byte code. • Unnecessary on Android © Edward Dale, 2017 21
Problems © Edward Dale, 2017 22
Problem 1 Class is unintentionally removed/obfuscated Symptom: Runtime crash java.lang.NoClassDefFoundError:
Failed resolution of: Lcom/freeletics/LoginActivity; © Edward Dale, 2017 23
Problem 1 Class is unintentionally removed/obfuscated Symptom: Runtime crash java.lang.NoClassDefFoundError:
Failed resolution of: Lcom/freeletics/LoginActivity; Solution: Ensure class is kept -keep com.freeletics.LoginActivity © Edward Dale, 2017 24
Problem 2 Code references a class not available Symptom:: Build
failure Warning: rx.internal.util.unsafe.ConcurrentCircularArrayQueue: can't find referenced class sun.misc.Unsafe ... Warning: there were 47 unresolved references to classes or interfaces. © Edward Dale, 2017 25
Problem 2 Code references a class not available Symptom:: Build
failure Warning: rx.internal.util.unsafe.ConcurrentCircularArrayQueue: can't find referenced class sun.misc.Unsafe ... Warning: there were 47 unresolved references to classes or interfaces. Solution: Don't warn about classes unavailable on Android -dontwarn sun.misc.Unsafe © Edward Dale, 2017 26
Problem 3 Adding a new library breaks build Symptom: Build
failure © Edward Dale, 2017 27
Problem 3 Adding a new library breaks build Symptom: Build
failure Solution: Google Should only happen with non-Android-specific libraries. Android-specific Libraries can add a ProGuard configuration that should be used. © Edward Dale, 2017 28
The Future we are also working on R8, which is
a Proguard replacement for whole program minification and optimization3 — James Lau, Product Manager 3 https://android-developers.googleblog.com/2017/08/next-generation-dex-compiler-now-in.html © Edward Dale, 2017 29
The Future • D8 is a dexer that converts java
byte code to dex code. • R8 is a java program shrinking and minification tool that converts java byte code to optimized dex code. • R8 is a Proguard replacement for whole-program optimization, shrinking and minification. R8 uses the Proguard keep rule format for specifying the entry points for an application. © Edward Dale, 2017 30
Questions? Edward Dale @scompt Freeletics https://www.freeletics.com © Edward Dale, 2017
31
Citations • http://knowyourmeme.com/memes/yao-ming-face-bitch- please © Edward Dale, 2017 32