Home » Android » java – how Android source code minify and obfuscate?

java – how Android source code minify and obfuscate?

Posted by: admin June 15, 2020 Leave a comment

Questions:

I had done my apps, any idea to minify the Android and Java code?
can it save the apk file size and improve performance? compare to unminify source code.

How to&Answers:

Enable shrinkResources in your build type. Note that it requires minify to be enabled.
In your Gradle file:

android {
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
        }
    }
}

The accepted answer is now outdated, so I added this answer if someone else stumbles upon this question.

Answer:

You can use ProGuard for this. Note however that your code will be obfuscated when it comes to crash reports etc so you need to keep obfuscation maps to be able to retrieve the stack traces between versions etc.
It does however protect you a lot better from reverse engineering your .APK.

More [email protected] Developers:
http://developer.android.com/tools/help/proguard.html

Answer:

Just enable ProGuard, it shrinks and obfuscates your application. It is included with the Android developer tools.

Answer:

There are three part

  1. minifyEnabled
  2. useProguard
  3. shrinkResources

if you want to remove unused part of coding then you can use shrinkResources true

if you don’t want to use default files like dmp.txt,mapping.txt,seeds.txt,usage.txt etc then you should use useProguard false

if you want to shrink your code and resource then you have to use minifyEnabled true

for more details refer this link

Answer:

Minification makes little sense in non scripting languages. What you can do is to use ProGuard to i.e. remove unused portions of the code, but as the major bloater in Android application are usually resources (drawables), ensure you do not have i.e. too many of them, or too big in size.

Answer:

This worked for me and i disable instant run

buildTypes {
        release {
            minifyEnabled true
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }

in proguard-rules.pro

-ignorewarnings
-keep class * {
    public private *;
}