Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how Android source code minify and obfuscate?

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.

like image 811
crossRT Avatar asked Dec 02 '12 13:12

crossRT


2 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.

like image 145
Rickard Avatar answered Oct 01 '22 21:10

Rickard


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 info@Android Developers: http://developer.android.com/tools/help/proguard.html

like image 32
Nicklas Gnejs Eriksson Avatar answered Oct 01 '22 21:10

Nicklas Gnejs Eriksson