Introducing some ways to increase security for Android App

Tram Ho

Some ways to increase security for Android App

1. Using Proguard

ProGuard is a built-in tool in Android Studio, with features that make your application source code compact (for ease of distribution), confusing (renaming classes, functions, variables, .. read to prevent decompile), ultimately it is optimized to make the application run faster. It is recommended to use ProGuard in both development (debug, staging) and release (release) environments, if only using it in the release product but ignoring its use when running in the development environment can causing the app to crash unexpectedly on release…

To configure, add the following code to the file build.gradle

In the above configuration section using ProGuard, the file proguard-rules.pro is an additional configuration file about how ProGuard works.

When ProGuard messes up the code, it renames the classes, many 3rd party reference classes are also converted, which can lead to errors and crashes. In case you want not to mess up a certain class you use the keep configuration, for example in the file: proguard-rules.pro we add

With the above code, will keep the classes and methods in the folder com.myapp.entity

2. Block rooted devices

Rooting the device helps us to control and install the device as we want, but besides that, it can affect the security of your information. Our App can be hacked and information stolen. So we should block rooted devices from using the App to ensure safety (if necessary).

There are many ways to help us check if the device is rooted or not, but the fastest and also relatively accurate way is to use the rootbear library ( https://github.com/scottyab/rootbeer ) to detect. In addition, if we want, we can also write our own to optimize.

Usage is also very simple as follows:

3. Block taking screenshots when using App

To reduce the risk of images being captured while using the app, photoshopped, then used for malicious purposes such as fraud, etc. We should prevent users from taking screenshots in certain screens that need to be protected. password, or even the App.

To use setFlag FLAG_SECURE for window

Reference: https://developer.android.com/reference/android/view/WindowManager.LayoutParams

Conclude

Above are some ways to increase security when we develop App on android. You can also apply these methods with different libraries and functions to suit each framework (if any). Thank you for watching.

Share the news now

Source : Viblo