MyFamilyTracker
Real-time family location sharing — Firebase Realtime DB for sub-second propagation, WorkManager + ForegroundService for OS-compliant background collection, geofencing via Google Maps API.
In this article, we will discuss how to use ProGuard and R8 to shrink and obfuscate your Android app, and how to debug release builds.
As a solo Android developer with over 13 years of experience, I have worked on numerous Android applications, and one of the most critical aspects of releasing a production-ready app is optimizing its size and performance. In this article, we will discuss how to use ProGuard and R8 to shrink and obfuscate your Android app, and how to debug release builds.
When we talk about optimizing an Android app, we are usually referring to the process of making the app smaller and faster. This is crucial because a smaller app size results in faster download times, lower storage requirements, and improved performance. However, this process can be complex and requires careful consideration.
ProGuard and R8 are two popular tools used for shrinking and obfuscating Android apps. ProGuard is a Java obfuscator that can rewrite and obfuscate the code, making it more difficult for reverse engineers to understand. R8 is a new tool introduced by Google that is specifically designed for Android apps and is more efficient and effective than ProGuard.
To shrink an Android app with R8, we need to add the following configuration to our
build.gradleandroid {
// ...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
// Use R8 instead of ProGuard
shrinkResources true
// Enable the following to shrink the APK size
// shrinkResources true
}
}
}We can also configure the ProGuard rules to exclude certain classes or methods that we don't want to be obfuscated. For example:
android {
// ...
buildTypes {
release {
// ...
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
// Exclude the Retrofit library
-keep class retrofit2.** { *; }
-keep interface retrofit2.** { *; }
}
}
}To obfuscate an Android app with ProGuard, we need to enable it in the
build.gradleandroid {
// ...
buildTypes {
release {
// ...
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
minifyEnabled true
}
}
}We can also configure the ProGuard rules to exclude certain classes or methods that we don't want to be obfuscated. For example:
android {
// ...
buildTypes {
release {
// ...
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
-keep class retrofit2.** { *; }
-keep interface retrofit2.** { *; }
}
}
}When we enable ProGuard or R8, the class names and method names are obfuscated, making it difficult to debug the app. To debug release builds, we need to use the
debuggableapplicationAndroidManifest.xml<application
android:debuggable="false"
// ...>However, this will not work if we have enabled ProGuard or R8. Instead, we need to use the following configuration in the
build.gradleandroid {
// ...
buildTypes {
debug {
// ...
debuggable true
}
release {
// ...
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
shrinkResources true
}
}
}debuggableapplicationAndroidManifest.xmldebugSudarshan Chaudhari
AI Systems Builder / Product Engineer
Bangkok, Thailand
Solo Android developer with 13+ years in QA, building Android apps, AI automation systems, and developer tools at SudarshanTechLabs.
Related Posts
Related Apps
Real-time family location sharing — Firebase Realtime DB for sub-second propagation, WorkManager + ForegroundService for OS-compliant background collection, geofencing via Google Maps API.
Building something? Available for Android dev and QA consulting.
Work with meComments — powered by Giscus
Real-time family location sharing — Firebase Realtime DB for sub-second propagation, WorkManager + ForegroundService for OS-compliant background collection, geofencing via Google Maps API.
ReadPrivate dream journal — structured entry capture, pattern tagging, and optional Claude-powered insight generation. All data stays on-device by default.
ReadWorkout tracker — exercise logging with set/rep/weight history, goal progression, and local Room DB persistence. No account, no cloud sync required.
Read