Code Hardening Against Reverse Engineering on Android and iOS: What It Protects, What It Doesn’t, and What to Add

Code Hardening Against Reverse Engineering on Android and iOS: What It Protects, What It Doesn’t, and What to Add

Once a mobile app reaches a customer’s phone, anyone with the right tools can download, unpack and study it. For banking and fintech apps, this means the logic behind logins, payments and security checks is open to analysis unless it is properly protected.

Code hardening is the essential first layer of defence against reverse engineering. It is most effective as part of a layered approach, where code encryption, runtime protection and server-side checks each cover a different stage of an attack. In this blog, we explain what code hardening protects on Android and iOS, how each technique works best, and which layers to combine it with.

TLDR

  • Code hardening makes reverse engineering slow and difficult by hiding names, strings and program logic, and by encrypting code and native libraries.

  • R8 and ProGuard rename and shrink code to reduce app size, so they should not be treated as reverse engineering protection.

  • No single control protects a banking app on its own. Strong code hardening works best combined with anti-tampering, runtime protection and server-side checks, on both Android and iOS.

What does code hardening actually protect?

Code hardening protects the readability of your app. It makes reverse engineering slower and harder, so an attacker struggles to understand how the app works from the compiled binary, which is usually the first step before tampering with it. OWASP’s MASVS lists this as an “anti-static analysis” control under MASVS-RESILIENCE.

What it guards in practice is the information an attacker would use to plan an attack: the names of security functions, hardcoded endpoints and keys, the structure of detection checks and proprietary business logic.

How Android and iOS differ

The two platforms start from very different places, which is why iOS app obfuscation needs its own attention.

  • Android: Java and Kotlin code is compiled to DEX bytecode, which can often be decompiled back into readable, Java-like code. Without strong code hardening, the app’s logic is close to its source.

  • iOS: Swift and Objective-C are compiled to native Mach-O binaries, so decompilation is less direct. However, Objective-C class names, selectors and Swift metadata often remain in the binary even after symbols are stripped, and that metadata can point an attacker straight to sensitive functions such as jailbreak checks.

Code hardening techniques and the layers that strengthen them

Each code hardening technique protects a different part of the app, and each becomes stronger when it is paired with another layer. The table shows what each technique protects and what it works best alongside.

Technique What it protects Works best alongside
Identifier renaming Meaningful class, method and field names String encryption and control-flow obfuscation, so the logic is hidden as well as the names
String encryption Endpoints, keys, error messages and detection artefacts Runtime protection that detects hooking and memory inspection while strings are in use
Control-flow flattening The natural order of conditions and branches in a function Anti-debugging and hooking detection, which protect the function while it runs
Arithmetic obfuscation and opaque constants Algorithm constants and simple calculations Runtime protection for the functions that rebuild these values
Code and native library encryption Whole DEX files and native libraries, protected from static extraction Integrity checks and runtime protection while the code is decrypted for use
Symbol stripping and metadata cleaning Function names and, on iOS, Objective-C and Swift metadata String encryption, since some metadata must remain for the runtime to work
Resource and asset encryption Configuration files, scripts and bundled models Runtime protection and server-issued keys

Code hardening protects the app at rest. Pairing it with runtime protection extends that protection to the moment the app runs.

Why R8 and ProGuard are not enough on their own

R8 is Android’s app optimiser. According to Android’s own documentation, it shortens the names of classes, fields and methods “to reduce the size of the DEX file”, alongside removing unused code and optimising what remains. Size and performance are the stated goals, and the documentation does not present this renaming as a security feature.

That matters because R8 and ProGuard leave several gaps that dedicated code hardening is designed to fill:

  • They do not encrypt strings, so hardcoded endpoints and keys remain readable.

  • They do not obfuscate control flow or add anti-tampering and runtime checks.

  • Keep rules often preserve the names of classes that use reflection or serialisation, which can include sensitive ones.

  • They only cover Java and Kotlin code on Android, so they offer nothing for native libraries or iOS apps.

Why no single layer is enough

Code hardening is built to protect the app at rest, and it does that job well. Once the app is running on a device the attacker controls, other layers need to work alongside it, because protected strings, libraries and functions must be used at runtime.

Four areas need a layer that works together with code hardening:

  • Runtime manipulation: On a rooted or jailbroken device, hooking frameworks can intercept functions while they run. Runtime protection detects these tools, while code hardening makes the right functions much harder to find in the first place.

  • Tampering and repackaging: An attacker may try to modify the app, re-sign it and distribute a cloned version. Integrity checks and repackaging detection confirm that the running app is the one you built.

  • Secrets stored in the app: Encryption keeps keys and tokens hidden in the binary. Replacing static secrets with server-issued, short-lived tokens leaves even less of value inside the app.

  • Trust on the server: Whether an API request is genuine is decided on the backend, so server-side validation completes the protection that starts in the app.

OWASP’s MASVS takes the same layered view. It treats obfuscation, anti-tampering and runtime self-protection as defence-in-depth measures that work together, and notes that every app must still meet the rest of its security controls.

For how build-time hardening and runtime protection fit together, read our guide to what mobile app shielding actually includes.

How to combine code hardening with runtime and server-side protection

The strongest protection comes from layers that cover each other. Code hardening hides how runtime checks work, and runtime checks protect the hardened code while it runs, so each makes the other harder to defeat.

Layer What it adds
Build-time code hardening Obfuscation, string encryption and DEX and native library encryption keep logic, keys and security checks unreadable in the binary
Integrity and repackaging detection Confirms that the running app is the one you built and signed
Runtime protection Detects root, jailbreak, hooking, debuggers, emulators and man-in-the-middle attempts, and triggers a response such as blocking a transaction
API binding with runtime-bound tokens Lets the backend accept only calls from a genuine app instance, with single-use tokens instead of static keys
Server-side validation Confirms the app, device and session before the backend honours a request
Release-build scanning Confirms that every layer shipped and that no secrets remain in plain text

Two practices make the whole stack more effective.

  • Protect sensitive code with more than renaming. Encrypt strings, DEX files and native libraries that hold detection checks, cryptographic routines and payment logic, so the code an attacker most wants to read is not visible in the binary.

  • Test the release build, not the source. Scan the final APK and IPA to confirm that hardening was applied, that no secrets remain in plain text and that runtime checks are present, because build settings can change between releases.

Define in advance whether a failed check should log, warn or block, based on the risk of the action, so that legitimate customers are not locked out.

For help choosing a runtime protection tool, read our guide to the best RASP tools for mobile apps.

How Bugsmirror helps

Bugsmirror’s products are built to work as layers, with each one covering a different stage of an attack.

  • Bugsmirror Shield provides the code hardening layer. It protects the app at build time with string encryption, DEX encryption and native library encryption, and detects code modification and repackaged apps. It supports Android and iOS, fits into the build through Gradle and IDE plugins, and can protect APK and IPA files without access to source code.

  • Bugsmirror Defender provides the runtime layer. It detects and blocks more than 200 runtime threats, including root and jailbreak, hooking frameworks, debuggers, emulators, tampering and man-in-the-middle attempts. It also supports server-side device and app validation and sends security events to ThreatLens for central visibility.

  • Trust API Bind extends protection to the API layer by binding every API call to a trusted app instance, a live runtime token and a real user session, using unique tokens that cannot be reused.

  • CodeLock runs static analysis on the final APK and IPA, detecting more than 50 types of vulnerabilities, including hardcoded keys, tokens and credentials.

Together, they give a banking app layered protection: code that is hard to read, an app that defends itself at runtime, APIs that accept only genuine calls and releases that are checked before they ship.

To see how your current build holds up against reverse engineering, book a free mobile app security audit with the Bugsmirror team.

FAQs:

  1. Is code hardening enough to protect a banking app on its own?

    Ans: Code hardening is an essential layer, but no single control protects a banking app on its own. It works best combined with runtime protection, integrity checks and server-side validation, so that the app is protected both at rest and while it runs.

  2. Is R8 enough to protect an Android banking app?

    Ans: R8 is not enough on its own. It shortens names to reduce app size and removes unused code, but it does not encrypt strings, obfuscate control flow or add anti-tampering and runtime checks, all of which a banking app needs.

  3. Do iOS apps need code hardening if they are compiled to native code?

    Ans: iOS apps still need code hardening. Native code is harder to reverse engineer than Android bytecode, but Objective-C and Swift metadata, symbols and strings often remain in the binary and can lead an attacker to sensitive functions.

  4. Does code hardening slow down a mobile app?

    Ans: Well-configured code hardening has a small performance cost. Applying the heavier techniques, such as control-flow flattening, to the most sensitive code keeps the impact low.

Share this article

Help others discover this content

Don’t give fraud a way in. Secure every layer of your mobile app.

100M+

Users Protected

100+

Apps Secured

1000+

Apps Hardened

Emulator detected
Session blocked