🔒 Protect your Android app code (2024)

Android security

🔒 Protect your Android app code (2)

As an Android developer, you will face an issue.
Your code is available to everyone.

If someone wants to know how your app works, no matter what you do, he will succeed. In security, there is no perfect protection.

The goal of this article is to provide you with some tools and tips to protect your app. Please note that decompiling an app to copy is not legal. You should only decompile your own app.

In this article, we will cover the following topics:
1. How to obtain the APK file
2. How to decompile the code
3. How attackers can obtain information
4. How to protect against decompilation

Multiple open doors are available for attackers. Read the decompiled app code. Read the UI displayed. Read the RAM. Read network traffic.

Non minified codebase
Some apps do not minify the code. Minification makes it harder to read decompiled by replacing methods and variables names with “a”, “b”, “c”, etc.

Resources
Android resources like strings and layout are open doors for attackers. With strings, it’s sometimes possible to know what the code is doing. Raw folder is also a great entry point.

Strings
Any string constant in the code will be fully readable.

Classes that are never minified like Activity, View, @Keep…
To have the view inflate working, the views will never be minified. So, the name and package name you give to your views and activities will be fully readable.

Assets folder
Keep in mind the assets folder is accessible without any protection. Anything you put in this folder is public.

Kotlin Intrinsics
Kotlin automatically checks nullability of variables, fields and parameters. To do that, Kotlin uses the Intrinsics class. Intrinsics check every parameter and add the name of the variable in the error message inside a readable string. This is another entry point of attack.

Kotlin data class
A Kotlin data class automatically generates the toString(). The “issue” is that the data class name and field name will be visible in the string inside the toString() method.

View dump
On a non-debug APK, the layout inspector does not work. However, you can dump the UI using uiautomator by running the command adb shell uiautomator dump. This will retrieve the entire get UI DOM of the screen displayed on your device.

Rooted device
With a rooted device, you can both, analyse the RAM at runtime, and pull the internal storage.

Network
To analyse network calls, you can use a proxy or tools like Wireshark or Charles.

AndroidManifest
The AndroidManifest is one other open door that the system will use. Indeed, the manifest lists every activity, receiver, services… By knowing the first Activity of an app, attackers can follow the call flow that the Android OS will do. So, attackers will be able to follow step by step from the Application.onCreate to every Activity.onCreate.

Minify, shrink and Obfuscate
The first step to protect against decompilation is to use obfuscation. Enable it via minifyEnabled in your app/build.gradle.kts. This will reduce the size of the code and make reverse engineer harder. R8 will be use using proguard files for configuration. More information can be found on the Android official documentation.

Never put a key in clear in string
There are robots on internet which crawl the PlayStore and decompile apps searching for secrets via static code analysis. The main target of these robots are non-protected strings with API keys inside. To protect information inside an application, there are multiple solutions depending on the level of security you want to have. Here are some solutions:

Base64, Zip, Gzip
This is the “easier” and less robust way to protect against basic code analysis. By base64 encoding your secret, it will be more difficult to know that there is a secret in the first place.

Native code via jni
This approach is a little bit more secure than Base64 approach. But keep in mind, this still possible to decompile the .so file and read your secret.

RSA & AES
Using RSA to exchange the key and AES to encrypt provides better better protection (although not perfect as there is no perfect solution).

Remove Kotlin Intrinsics to not provide your field and variable name
There is a way to remove these Kotlin nullability checks. However, keep in mind that in a fail-fast approach, this is not a good practice. At least, you will give less information and reduce a your bytecode. Great article here and by Jake Wharton.

Kotlin data class - toString
To hide class name and field names, you can override your data class’s toString() method.

R8 option
R8 has an option to make attacks harder. For more information, check out this great article. With this option, all your minified classes will be put on the same package.

-repackageclasses 'defpackage'

Compose
With the use of Jetpack Compose, there is no need for layouts, views, fragments. You may even be tempted to have a mono activity. By doing this, you will reduce the surface of attack.

PlayStore anti tamper protection
Here is a great article about it. Otherwise the PlayStore hase released its own anti-tamper protection.

AabResGuard
Tool from bytedance that I kept up-to date with latest version of BundleTool. This tool obfuscate resources: layouts, strings...

🔒 Protect your Android app code (2024)
Top Articles
Pit Trading - OPIS, A Dow Jones Company
Style Score Education
Encore Atlanta Cheer Competition
Stretchmark Camouflage Highland Park
Euro (EUR), aktuální kurzy měn
Wordscapes Level 5130 Answers
Practical Magic 123Movies
Wizard Build Season 28
Mychart Mercy Lutherville
Lexington Herald-Leader from Lexington, Kentucky
craigslist: south coast jobs, apartments, for sale, services, community, and events
Soap2Day Autoplay
Cinepacks.store
Cars For Sale Tampa Fl Craigslist
Prices Way Too High Crossword Clue
Tiraj Bòlèt Florida Soir
Hallelu-JaH - Psalm 119 - inleiding
Reddit Wisconsin Badgers Leaked
All Buttons In Blox Fruits
Mary Kay Lipstick Conversion Chart PDF Form - FormsPal
Hellraiser III [1996] [R] - 5.8.6 | Parents' Guide & Review | Kids-In-Mind.com
Clear Fork Progress Book
Jalapeno Grill Ponca City Menu
Robeson County Mugshots 2022
Kcwi Tv Schedule
Homeaccess.stopandshop
Used Safari Condo Alto R1723 For Sale
Red Cedar Farms Goldendoodle
Anesthesia Simstat Answers
manhattan cars & trucks - by owner - craigslist
Darknet Opsec Bible 2022
Craigslist Sf Garage Sales
Deepwoken: Best Attunement Tier List - Item Level Gaming
Grandstand 13 Fenway
Memberweb Bw
Top-ranked Wisconsin beats Marquette in front of record volleyball crowd at Fiserv Forum. What we learned.
Powerspec G512
Legit Ticket Sites - Seatgeek vs Stubhub [Fees, Customer Service, Security]
Timberwolves Point Guard History
Craigslist Odessa Midland Texas
All Characters in Omega Strikers
5A Division 1 Playoff Bracket
Www Craigslist Com Atlanta Ga
Deepwoken: How To Unlock All Fighting Styles Guide - Item Level Gaming
How I Passed the AZ-900 Microsoft Azure Fundamentals Exam
Citizens Bank Park - Clio
Flappy Bird Cool Math Games
Booknet.com Contract Marriage 2
Greatpeople.me Login Schedule
Syrie Funeral Home Obituary
Sc Pick 3 Past 30 Days Midday
CPM Homework Help
Latest Posts
Article information

Author: Mrs. Angelic Larkin

Last Updated:

Views: 5704

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Mrs. Angelic Larkin

Birthday: 1992-06-28

Address: Apt. 413 8275 Mueller Overpass, South Magnolia, IA 99527-6023

Phone: +6824704719725

Job: District Real-Estate Facilitator

Hobby: Letterboxing, Vacation, Poi, Homebrewing, Mountain biking, Slacklining, Cabaret

Introduction: My name is Mrs. Angelic Larkin, I am a cute, charming, funny, determined, inexpensive, joyous, cheerful person who loves writing and wants to share my knowledge and understanding with you.