What is the main purpose of ProGuard in Android development?
ProGuard shrinks, optimizes, and obfuscates your app's code to reduce APK size and make reverse engineering harder.
Click to reveal answer
intermediate
How does R8 differ from ProGuard?
R8 combines shrinking, optimization, and obfuscation in one step and is the default code shrinker in Android Studio since version 3.4.
Click to reveal answer
beginner
What is a 'keep rule' in ProGuard or R8?
A keep rule tells the optimizer not to remove or rename certain classes or methods that are needed at runtime.
Click to reveal answer
beginner
Why is obfuscation important in Android apps?
Obfuscation renames classes and methods to unreadable names, making it harder for others to understand or copy your code.
Click to reveal answer
intermediate
When should you disable code shrinking in your Android app?
You might disable shrinking during debugging to speed up build times or if shrinking causes issues with reflection or libraries.
Click to reveal answer
Which tool is the default code shrinker in Android Studio since version 3.4?
AR8
BProGuard
CDexGuard
DLint
✗ Incorrect
R8 replaced ProGuard as the default shrinker and optimizer in Android Studio 3.4 and later.
What does a 'keep rule' in ProGuard or R8 do?
APrevents removal or renaming of specified code
BCompresses images
CRemoves unused code
DGenerates logs
✗ Incorrect
Keep rules protect code from being removed or renamed during shrinking and obfuscation.
Which of the following is NOT a benefit of using ProGuard or R8?
AReducing APK size
BImproving app performance by optimizing code
CMaking reverse engineering harder
DAutomatically fixing runtime bugs
✗ Incorrect
ProGuard and R8 do not fix runtime bugs automatically; they focus on shrinking, optimizing, and obfuscating code.
Why might you need to add keep rules when using R8?
ATo speed up compilation
BTo prevent removal of code used via reflection
CTo enable multi-threading
DTo increase APK size
✗ Incorrect
Code accessed by reflection might be removed if not kept explicitly with keep rules.
What happens if you disable code shrinking in your Android app?
AObfuscation is improved
BApp runs faster
CApp size usually increases
DApp crashes immediately
✗ Incorrect
Disabling shrinking keeps all code, which usually increases the app size.
Explain the roles of ProGuard and R8 in Android app optimization.
Think about how these tools help reduce app size and protect code.
You got /4 concepts.
Describe why and when you would use keep rules in your Android project.
Consider cases where code is used indirectly and must not be removed.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of enabling minifyEnabled true in your Android app's release build?
easy
A. To automatically generate UI layouts
B. To increase the app's debug information for easier troubleshooting
C. To disable ProGuard and R8 optimizations
D. To shrink and optimize the app code by removing unused parts
Solution
Step 1: Understand the role of minifyEnabled
Setting minifyEnabled true activates code shrinking and optimization tools like ProGuard and R8.
Step 2: Identify the effect on app code
These tools remove unused code and optimize the remaining code to reduce app size and improve performance.
Final Answer:
To shrink and optimize the app code by removing unused parts -> Option D
Quick Check:
minifyEnabled true = shrink and optimize [OK]
Hint: minifyEnabled true means code shrinking is ON [OK]
Common Mistakes:
Thinking it increases debug info instead of reducing code
Confusing minifyEnabled with disabling optimizations
Assuming it generates UI layouts automatically
2. Which of the following is the correct way to specify a ProGuard rules file in your build.gradle for release builds?
easy
A. proguardFiles 'proguard-rules.txt'
B. proguardFiles 'proguard-android-optimize.txt', getDefaultProguardFile('proguard-rules.pro')
C. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
D. minifyEnabled false
Solution
Step 1: Recall the standard syntax for ProGuard files
The correct syntax uses getDefaultProguardFile for the default file and then adds custom rules.
Step 2: Match the correct order and file names
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' correctly calls getDefaultProguardFile('proguard-android-optimize.txt') and then adds 'proguard-rules.pro'.
Final Answer:
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' -> Option C
5. You want to keep all classes in the package com.example.models but allow R8 to rename their members to reduce size. Which ProGuard rule should you use?
hard
A. -keepnames class com.example.models.**
B. -keepclassmembers class com.example.models.** { *; }
C. -keep class com.example.models.** { *; }
D. -keepclassmembernames class com.example.models.** { *; }
Solution
Step 1: Understand the difference between -keep and -keepnames
-keep prevents removal and renaming; -keepnames prevents renaming but allows removal.
Step 2: Match the requirement
You want to keep classes but allow member renaming, so -keepnames on classes is correct.
Final Answer:
-keepnames class com.example.models.** -> Option A
Quick Check:
Keep classes but rename members = -keepnames [OK]
Hint: -keepnames keeps class names but allows member renaming [OK]
Common Mistakes:
Using -keep which prevents renaming
Confusing -keepclassmembers with -keepnames
Assuming -keepclassmembernames keeps classes
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.