Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
Difference Between Proguard and R8 in Android
Next article icon

Difference Between Proguard and R8 in Android

Last Updated : 23 Feb, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Proguard and R8 both are similar tools that are used for reducing the size of our APK and increase the performance of our APK by shrinking the unused resources. In this article, we will take a look at: 

  • What is Proguard?
  • What is R8?
  • Difference between Proguard and R8.

What is Proguard? 

Proguard is a java tool in Android that helps to do the following things such as: 

  • It removes the unused classes and methods from your app which helps to reduce the size of your APK.
  • It makes your application difficult to reverse engineer by obfuscating the code.
  • It reduces the size of your application.

How to enable Proguard in your Application? 

To enable proguard in your application Navigate to the Gradle Scripts > build.gradle(:app) and then you will get to see a method called buildTypes. 

buildTypes {

       release {

           minifyEnabled true

           proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

       }

}

In this block of code, we have to change minifyEnabled to true to activate our Proguard. This code of Proguard is written under the release block so it will only work on the release build of your APK. It will activate the proguard which will take it from the file named as

'proguard-android.txt'.  

What is R8? 

R8 is another tool that will convert your java byte code into an optimized format of dex code. It will check the whole application and will remove the unused classes and methods. It helps us to reduce the size of our APK and to make our app more secure. R8 uses similar proguard rules to modify its default behavior. 

How to enable R8 in your Application?

R8 is already present in your application you just have to enable it. To enable it just Navigate to the Gradle Scripts > build.gradle(:app) and then you will get to see a method called buildTypes.

buildTypes {

       release {

           minifyEnabled true

       }

}

In this block of code, we have to change minifyEnabled to true to activate R8. This code for R8 is written under the release block which is only working on the release build of your APK. 

Difference Between Proguard and R8.

  • R8 has more Kotlin support than that of Proguard.
  • R8 is having a faster processing time than Proguard which reduces build time.
  • R8 gives better output results than Proguard.
  • R8 reduces the app size by 10 % whereas Proguard reduces app size by 8.5 %.
  • The android app having a Gradle plugin above 3.4.0 or above then the project uses R8 by default with Proguard rules only.

Proguard

Proguard

In Proguard java compiler converts Apps code into JAVA bytecode and proguard will converts this bytecode into the optimized java bytecode. This java bytecode is then optimized by dex into Optimized Dalvik bytecode. The conversion process of apps code to optimized Dalvik bytecode is a four steps process.  

R8

R8

In R8 java compiler converts Apps code in JAVA bytecode and then R8 will directly convert JAVA bytecode into Optimized Dalvik bytecode. The conversion process of apps code to Optimized Dalvik bytecode is a three steps process that is faster in comparison with proguard. 

Difference Table 

Proguard

R8

Proguard is having lesser speed in comparison with R8 which affects the build time.R8 is having a faster processing time which helps developers in reducing build time.
The output quality by using proguard is not superior. The output quality using R8 is superior.
Proguard reduces app size by 8.5 %.R8 reduces app size by 10 %.

The conversion process of converting apps code to Optimized Dalvik bytecode is as follows : 

Apps Code > Java bytecode > Optimized java bytecode > Optimized Dalvik bytecode.

The conversion process of converting apps code to Optimized Dalvik bytecode is as follows : 

Apps code > Java bytecode > Optimized Dalvik bytecode.

Proguard is only supported for the gradle plugin which is below 3.4.0R8 is only supported for the gradle plugin of 3.4.0 and above.
Peephole Optimizations in Proguard is around 520.Peephole Optimizations in R8 is around 6.
No of the steps in converting of Apps code to Optimized Dalvik code is 4.No of the steps in converting Apps code to Optimized Dalvik bytecode is 3. 
Proguard is not having Kotlin specific optimizations. R8 is having Kotlin specific optimizations. 
Proguard does not propagate constant arguments. R8 propagate constant arguments. 

Conclusion

While R8 is faster than proguard as there are fewer number steps. It reduces the size of the app in an optimized manner with a default compile-time optimizer. 


Next Article
Difference Between Proguard and R8 in Android

C

chaitanyamunje
Improve
Article Tags :
  • Technical Scripter
  • Difference Between
  • Android
  • Technical Scripter 2020
  • Android-Misc

Similar Reads

    Difference Between Linux and Android
    Linux and Android are important Operating systems in the tech global, each serving distinct functions and catering to one-of-a-kind user needs. The majority of individuals believe that Android and Linux are operating systems. Android is a mobile phone OS, whereas Linux is used on servers and desktop
    6 min read
    Difference between iOS and Android
    1. iOS: iOS is a mobile operating system that is provided by Apple Incorporation. It is mainly designed for Apple mobile devices like iPhone and iPod Touch. It was earlier known as iPhone OS. It is a Unix-like operating system that is based on Darwin's (BSD) operating system. It is the world’s secon
    3 min read
    Difference between Windows and Android
    1. Windows : Windows is a group of various proprietary graphical operating systems which is provided by Microsoft Incorporation. It is also known as Microsoft Windows. It currently includes Windows NT and Windows IoT as members of its family. Earlier it included Windows 9x, Windows Mobile and Window
    4 min read
    Difference between FreeBSD and Android
    1. FreeBSD : FreeBSD is a free and open source operating system which is provided The FreeBSD Project. It was designed on the basis of the two Unix-like operating systems Berkeley Software Distribution (BSD) and Research Unix. It has quite similarities with Linux operating system. It was one of the
    2 min read
    Difference between AIX and Android
    1. AIX : AIX is a series of proprietary operating systems which is provided by IBM. AIX stands for Advanced Interactive eXecutive. Initially it was designed for the IBM RT PC RISC workstation and later it was used for various hardware platforms like IBM RS/6000 series, PowerPC-based systems, System-
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences