DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Full-Stack Observability Essentials: Explore the fundamentals of system-wide observability and key components of the OpenTelemetry standard.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • HTML5 on Android 4.0: Way Better, Still Behind iOS 5
  • How to Make Android Development Less Frustrating
  • How it Feels to Switch from Eclipse to Android Studio
  • The 12 Biggest Android App Development Trends in 2023

Trending

  • Supercharge Your Communication With Twilio and Ballerina
  • Send Your Logs to Loki
  • A Complete Guide to Open-Source LLMs
  • The Emergence of Cloud-Native Integration Patterns in Modern Enterprises
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Enabling ProGuard for Android

Enabling ProGuard for Android

ProGuard helps obfuscate Android code, but it also provides several ways to improve the speed of your app. Learn how to enable it here.

Maheshwar Ligade user avatar by
Maheshwar Ligade
CORE ·
Feb. 07, 17 · Tutorial
Like (5)
Save
Tweet
Share
27.04K Views

Join the DZone community and get the full member experience.

Join For Free

Enabling ProGuard in Android Studio is a really easy task, but I am getting this question frequently on StackOverflow, which motivated me to write this simple article.

Here is the question on StackOverflow. I have already provided my answer here, but now I want to explore what ProGuard is and how to enable it.

What is ProGuard?

Ref - Wikipedia:

ProGuard is an open source command-line tool that shrinks, optimizes and obfuscates Java code. It is able to optimize bytecode as well as detect and remove unused instructions. ProGuard is open source software.

Proguard was developed by Eric P.F. Lafortune.

As per the definition, proguard will help you to not only obfuscate, but also optimize, shrink, and remove unused instructions as well.

I've asked many why they want to apply ProGuard to their projects, and I only encounter one answer, "we use it only for security purposes". This will not provide just security to your code. 

Features of ProGuard

  1. ProGuard also optimizes the bytecode, removes unused code instructions, and obfuscates the remaining classes, fields, and methods with short names.
  2. The obfuscated code makes your APK difficult to reverse engineer, which is especially valuable when your app uses security-sensitive features, such as licensing verification.

Enabling ProGuard in Android Studio

Below is a sample of how to enable default ProGuard in Android Studio.

  1. Go to the build.gradle file of app
  2. Enable the proguard minifyEnabled true
  3. Enable shrinkResources true to reduce the APK size by shrinking resources.
  4. proguardFiles getDefaultProguardFile('proguard-android.txt') to enable the default one. If you want to use your own proguard file then use the below rules.
buildTypes {  
  release {  
    debuggable false        
    minifyEnabled true        
    shrinkResources true      
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'   
  }    
  debug { 
    debuggable true   
    minifyEnabled true       
    shrinkResources true       
    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'   
  }
}

The link contains ProGuard settings for Android and other library settings:

  • Default ProGuard file
  • Gist with example
  • Proguard snippet for Android libraries
Android (robot)

Published at DZone with permission of Maheshwar Ligade. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • HTML5 on Android 4.0: Way Better, Still Behind iOS 5
  • How to Make Android Development Less Frustrating
  • How it Feels to Switch from Eclipse to Android Studio
  • The 12 Biggest Android App Development Trends in 2023

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: